summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-08 01:11:00 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-08 01:11:00 +0200
commitff9e9fb8c4fda04b3f0fe7d05c2d6d1971027de2 (patch)
tree1c995b81e8f5816fa77611e8ac6a6597a6deca59
parentnpm i @fosscord/server-util@1.3.42 (diff)
downloadserver-ff9e9fb8c4fda04b3f0fe7d05c2d6d1971027de2.tar.xz
:bug: fix channel subscription + ready payload
-rw-r--r--src/listener/listener.ts21
-rw-r--r--src/opcodes/Identify.ts14
2 files changed, 29 insertions, 6 deletions
diff --git a/src/listener/listener.ts b/src/listener/listener.ts

index b8ee84fd..ae15c971 100644 --- a/src/listener/listener.ts +++ b/src/listener/listener.ts
@@ -1,4 +1,4 @@ -import { db, Event, MongooseCache, UserModel, getPermission, Permissions } from "@fosscord/server-util"; +import { db, Event, MongooseCache, UserModel, getPermission, Permissions, ChannelModel } from "@fosscord/server-util"; import { OPCODES } from "../util/Constants"; import { Send } from "../util/Send"; import WebSocket from "../util/WebSocket"; @@ -36,12 +36,25 @@ function getPipeline(this: WebSocket, guilds: string[], channels: string[] = []) } export async function setupListener(this: WebSocket) { + const channels = await ChannelModel.find({ recipient_ids: this.user_id }, { id: true }).exec(); + console.log( + "subscribe to channels", + channels.map((x) => x.id) + ); const user = await UserModel.findOne({ id: this.user_id }).lean().exec(); var guilds = user!.guilds; - const eventStream = new MongooseCache(db.collection("events"), getPipeline.call(this, guilds), { - onlyEvents: true, - }); + const eventStream = new MongooseCache( + db.collection("events"), + getPipeline.call( + this, + guilds, + channels.map((x) => x.id) + ), + { + onlyEvents: true, + } + ); await eventStream.init(); eventStream.on("insert", (document: Event) => dispatch.call(this, document, { eventStream, guilds })); diff --git a/src/opcodes/Identify.ts b/src/opcodes/Identify.ts
index 74c98ede..43368367 100644 --- a/src/opcodes/Identify.ts +++ b/src/opcodes/Identify.ts
@@ -98,6 +98,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { verified: user.verified, bot: user.bot, accent_color: user.accent_color || 0, + banner: user.banner, }; const d: ReadyEventData = { @@ -130,7 +131,11 @@ export async function onIdentify(this: WebSocket, data: Payload) { version: 642, }, // @ts-ignore - private_channels: toObject(channels), + private_channels: toObject(channels).map((x: ChannelDocument) => { + x.recipient_ids = x.recipients.map((y: any) => y.id); + delete x.recipients; + return x; + }), session_id: "", // TODO analytics_token: "", // TODO connected_accounts: [], // TODO @@ -144,7 +149,12 @@ export async function onIdentify(this: WebSocket, data: Payload) { // @ts-ignore experiments: experiments, // TODO guild_join_requests: [], // TODO what is this? - users: [public_user], // TODO + users: [ + public_user, + ...toObject(channels) + .map((x: any) => x.recipients) + .flat(), + ].unique(), // TODO merged_members: merged_members, // shard // TODO: only for bots sharding // application // TODO for applications