diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-20 21:49:42 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-20 21:49:42 +0200 |
commit | 5cec6e43d4e193616458a7e9c74a486ceade7e93 (patch) | |
tree | d0728474d103bcd6743e365828b342b750902c33 /gateway/src | |
parent | :sparkles: route middleware test option (diff) | |
parent | :bug: fix relationships (diff) | |
download | server-5cec6e43d4e193616458a7e9c74a486ceade7e93.tar.xz |
Merge branch 'master' into unittests
Diffstat (limited to 'gateway/src')
-rw-r--r-- | gateway/src/listener/listener.ts | 4 | ||||
-rw-r--r-- | gateway/src/opcodes/Identify.ts | 38 | ||||
-rw-r--r-- | gateway/src/opcodes/index.ts | 1 |
3 files changed, 22 insertions, 21 deletions
diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts index ef3dd890..ae13cca7 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts @@ -32,7 +32,7 @@ export async function setupListener(this: WebSocket) { }); const guilds = members.map((x) => x.guild); const recipients = await Recipient.find({ - where: { user_id: this.user_id }, + where: { user_id: this.user_id, closed: false }, relations: ["channel"], }); const dm_channels = recipients.map((x) => x.channel); @@ -116,7 +116,7 @@ async function consume(this: WebSocket, opts: EventOpts) { .has("VIEW_CHANNEL") ) return; - // TODO: check if user has permission to channel + //No break needed here, we need to call the listenEvent function below case "GUILD_CREATE": this.events[id] = await listenEvent(id, consumer, listenOpts); break; diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index f6a4478f..d91cd7f2 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -88,20 +88,17 @@ export async function onIdentify(this: WebSocket, data: Payload) { const user_guild_settings_entries = members.map((x) => x.settings); const recipients = await Recipient.find({ - where: { user_id: this.user_id }, + where: { user_id: this.user_id, closed: false }, relations: ["channel", "channel.recipients", "channel.recipients.user"], // TODO: public user selection }); const channels = recipients.map((x) => { // @ts-ignore x.channel.recipients = x.channel.recipients?.map((x) => x.user); - // @ts-ignore - users = users.concat(x.channel.recipients); - if (x.channel.type === ChannelType.DM) { - x.channel.recipients = [ - // @ts-ignore - x.channel.recipients.find((x) => x.id !== this.user_id), - ]; + //TODO is this needed? check if users in group dm that are not friends are sent in the READY event + //users = users.concat(x.channel.recipients); + if (x.channel.isDm()) { + x.channel.recipients = x.channel.recipients!.filter((x) => x.id !== this.user_id); } return x.channel; }); @@ -111,16 +108,19 @@ export async function onIdentify(this: WebSocket, data: Payload) { }); if (!user) return this.close(CLOSECODES.Authentication_failed); - const public_user = { - username: user.username, - discriminator: user.discriminator, - id: user.id, - public_flags: user.public_flags, - avatar: user.avatar, - bot: user.bot, - bio: user.bio, - }; - users.push(public_user); + for (let relation of user.relationships) { + const related_user = relation.to + const public_related_user = { + username: related_user.username, + discriminator: related_user.discriminator, + id: related_user.id, + public_flags: related_user.public_flags, + avatar: related_user.avatar, + bot: related_user.bot, + bio: related_user.bio, + }; + users.push(public_related_user); + } const session_id = genSessionId(); this.session_id = session_id; //Set the session of the WebSocket object @@ -201,7 +201,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { // @ts-ignore experiments: experiments, // TODO guild_join_requests: [], // TODO what is this? - users: users.unique(), // TODO + users: users.unique(), merged_members: merged_members, // shard // TODO: only for bots sharding // application // TODO for applications diff --git a/gateway/src/opcodes/index.ts b/gateway/src/opcodes/index.ts index a6d13bfb..c4069589 100644 --- a/gateway/src/opcodes/index.ts +++ b/gateway/src/opcodes/index.ts @@ -21,5 +21,6 @@ export default { 8: onRequestGuildMembers, // 9: Invalid Session // 10: Hello + // 13: Dm_update 14: onLazyRequest, }; |