This commit is contained in:
Puyodead1 2023-03-18 19:50:38 -04:00
parent 7116a9a1b0
commit 5a7765c7dc
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
5 changed files with 58 additions and 51 deletions

View File

@ -26,7 +26,7 @@ import {
Sentry, Sentry,
WebAuthn, WebAuthn,
ConnectionConfig, ConnectionConfig,
ConnectionLoader ConnectionLoader,
} from "@fosscord/util"; } from "@fosscord/util";
import { Request, Response, Router } from "express"; import { Request, Response, Router } from "express";
import { Server, ServerOptions } from "lambert-server"; import { Server, ServerOptions } from "lambert-server";

View File

@ -53,7 +53,7 @@ export const NO_AUTHORIZATION_ROUTES = [
// Asset delivery // Asset delivery
/\/guilds\/\d+\/widget\.(json|png)/, /\/guilds\/\d+\/widget\.(json|png)/,
// Connections // Connections
/\/connections\/\w+\/callback/ /\/connections\/\w+\/callback/,
]; ];
export const API_PREFIX = /^\/api(\/v\d+)?/; export const API_PREFIX = /^\/api(\/v\d+)?/;

View File

@ -79,53 +79,60 @@ export async function onIdentify(this: WebSocket, data: Payload) {
this.user_id = decoded.id; this.user_id = decoded.id;
const session_id = this.session_id; const session_id = this.session_id;
const [user, read_states, members, recipients, session, application, connected_accounts] = const [
await Promise.all([ user,
User.findOneOrFail({ read_states,
where: { id: this.user_id }, members,
relations: ["relationships", "relationships.to", "settings"], recipients,
select: [...PrivateUserProjection, "relationships"], session,
}), application,
ReadState.find({ where: { user_id: this.user_id } }), connected_accounts,
Member.find({ ] = await Promise.all([
where: { id: this.user_id }, User.findOneOrFail({
select: MemberPrivateProjection, where: { id: this.user_id },
relations: [ relations: ["relationships", "relationships.to", "settings"],
"guild", select: [...PrivateUserProjection, "relationships"],
"guild.channels", }),
"guild.emojis", ReadState.find({ where: { user_id: this.user_id } }),
"guild.roles", Member.find({
"guild.stickers", where: { id: this.user_id },
"user", select: MemberPrivateProjection,
"roles", relations: [
], "guild",
}), "guild.channels",
Recipient.find({ "guild.emojis",
where: { user_id: this.user_id, closed: false }, "guild.roles",
relations: [ "guild.stickers",
"channel", "user",
"channel.recipients", "roles",
"channel.recipients.user", ],
], }),
// TODO: public user selection Recipient.find({
}), where: { user_id: this.user_id, closed: false },
// save the session and delete it when the websocket is closed relations: [
Session.create({ "channel",
user_id: this.user_id, "channel.recipients",
session_id: session_id, "channel.recipients.user",
// TODO: check if status is only one of: online, dnd, offline, idle ],
status: identify.presence?.status || "offline", //does the session always start as online? // TODO: public user selection
client_info: { }),
//TODO read from identity // save the session and delete it when the websocket is closed
client: "desktop", Session.create({
os: identify.properties?.os, user_id: this.user_id,
version: 0, session_id: session_id,
}, // TODO: check if status is only one of: online, dnd, offline, idle
activities: [], status: identify.presence?.status || "offline", //does the session always start as online?
}).save(), client_info: {
Application.findOne({ where: { id: this.user_id } }), //TODO read from identity
ConnectedAccount.find({ where: { user_id: this.user_id } }) client: "desktop",
]); os: identify.properties?.os,
version: 0,
},
activities: [],
}).save(),
Application.findOne({ where: { id: this.user_id } }),
ConnectedAccount.find({ where: { user_id: this.user_id } }),
]);
if (!user) return this.close(CLOSECODES.Authentication_failed); if (!user) return this.close(CLOSECODES.Authentication_failed);
if (!user.settings) { if (!user.settings) {

View File

@ -25,4 +25,4 @@ export * from "./dtos/index";
export * from "./schemas"; export * from "./schemas";
export * from "./imports"; export * from "./imports";
export * from "./config"; export * from "./config";
export * from "./connections" export * from "./connections";