1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 05:02:37 +01:00

🐛 fix channel subscription + ready payload

This commit is contained in:
Flam3rboy 2021-08-08 01:11:00 +02:00
parent 45a4cd2f1d
commit ff9e9fb8c4
2 changed files with 29 additions and 6 deletions

View File

@ -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 }));

View File

@ -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