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
|