summary refs log tree commit diff
path: root/src/gateway/opcodes/Identify.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gateway/opcodes/Identify.ts (renamed from gateway/src/opcodes/Identify.ts)25
1 files changed, 16 insertions, 9 deletions
diff --git a/gateway/src/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts

index 860000da..44db598c 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -18,16 +18,18 @@ import { PrivateSessionProjection, MemberPrivateProjection, PresenceUpdateEvent, + UserSettings, + IdentifySchema, } from "@fosscord/util"; import { Send } from "../util/Send"; import { CLOSECODES, OPCODES } from "../util/Constants"; import { genSessionId } from "../util/SessionUtils"; import { setupListener } from "../listener/listener"; -import { IdentifySchema } from "../schema/Identify"; // import experiments from "./experiments.json"; const experiments: any = []; import { check } from "./instanceOf"; import { Recipient } from "@fosscord/util"; +import { OrmUtils } from "@fosscord/util"; // TODO: user sharding // TODO: check privileged intents, if defined in the config @@ -50,15 +52,15 @@ export async function onIdentify(this: WebSocket, data: Payload) { const session_id = genSessionId(); this.session_id = session_id; //Set the session of the WebSocket object - + const [user, read_states, members, recipients, session, application] = await Promise.all([ User.findOneOrFail({ where: { id: this.user_id }, - relations: ["relationships", "relationships.to"], + relations: ["relationships", "relationships.to", "settings"], select: [...PrivateUserProjection, "relationships"], }), - ReadState.find({ user_id: this.user_id }), + ReadState.find({ where: { user_id: this.user_id } }), Member.find({ where: { id: this.user_id }, select: MemberPrivateProjection, @@ -83,7 +85,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { // TODO: public user selection }), // save the session and delete it when the websocket is closed - new Session({ + await OrmUtils.mergeDeep(new Session(), { user_id: this.user_id, session_id: session_id, // TODO: check if status is only one of: online, dnd, offline, idle @@ -96,12 +98,17 @@ export async function onIdentify(this: WebSocket, data: Payload) { }, activities: [], }).save(), - Application.findOne({ id: this.user_id }), + Application.findOne({ where: { id: this.user_id } }), ]); if (!user) return this.close(CLOSECODES.Authentication_failed); + if (!user.settings) { //settings may not exist after updating... + user.settings = new UserSettings(); + user.settings.id = user.id; + //await (user.settings as UserSettings).save(); + } - if (!identify.intents) identify.intents = BigInt("0x6ffffffff"); + if (!identify.intents) identify.intents = "30064771071"; this.intents = new Intents(identify.intents); if (identify.shard) { this.shard_id = identify.shard[0]; @@ -117,7 +124,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { return this.close(CLOSECODES.Invalid_shard); } } - var users: PublicUser[] = []; + let users: PublicUser[] = []; const merged_members = members.map((x: Member) => { return [ @@ -231,7 +238,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { const d: ReadyEventData = { v: 8, - application, + application: {id: application?.id??'', flags: application?.flags??0}, //TODO: check this code! user: privateUser, user_settings: user.settings, // @ts-ignore