From 0ed83c0b6c10a2ee9b6fbf684e557922b8160381 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 23 Jan 2026 11:35:11 +0100 Subject: [PATCH] Identify: add self as recipient for DMs with nonexistnt users --- src/gateway/opcodes/Identify.ts | 46 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index d6f146270..34732c381 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -16,11 +16,19 @@ along with this program. If not, see . */ -import { CLOSECODES, Capabilities, OPCODES, Payload, Send, WebSocket, setupListener } from "@spacebar/gateway"; +import { Capabilities, CLOSECODES, OPCODES, Payload, Send, setupListener, WebSocket } from "@spacebar/gateway"; import { Application, + Channel, + checkToken, Config, + CurrentTokenFormatVersion, + ElapsedTime, + emitEvent, + Emoji, EVENTEnum, + generateToken, + getDatabase, Guild, GuildOrUnavailable, Intents, @@ -33,32 +41,24 @@ import { ReadyGuildDTO, ReadyUserGuildSettingsEntries, Recipient, + Relationship, + Role, Session, SessionsReplace, - UserSettings, - checkToken, - emitEvent, - getDatabase, + Sticker, + Stopwatch, + timeFunction, + timePromise, TraceNode, TraceRoot, - Stopwatch, - timePromise, - ElapsedTime, - Channel, - Emoji, - Role, - Sticker, - VoiceState, + UserSettings, UserSettingsProtos, - generateToken, - CurrentTokenFormatVersion, - Relationship, - timeFunction, + VoiceState, } from "@spacebar/util"; import { check } from "./instanceOf"; import { In, Not } from "typeorm"; import { PreloadedUserSettings } from "discord-protos"; -import { DefaultUserGuildSettings, DMChannel, IdentifySchema, PrivateUserProjection, PublicUser, PublicUserProjection } from "@spacebar/schemas"; +import { ChannelType, DefaultUserGuildSettings, DMChannel, IdentifySchema, PrivateUserProjection, PublicUser, PublicUserProjection } from "@spacebar/schemas"; // TODO: user sharding // TODO: check privileged intents, if defined in the config @@ -479,9 +479,17 @@ export async function onIdentify(this: WebSocket, data: Payload) { // Remove ourself from the list of other users in dm channel channel.recipients = channel.recipients.filter((recipient) => recipient.user.id !== this.user_id); - const channelUsers = channel.recipients?.map((recipient) => recipient.user.toPublicUser()); + let channelUsers = channel.recipients?.map((recipient) => recipient.user.toPublicUser()); if (channelUsers && channelUsers.length > 0) channelUsers.forEach((user) => users.add(user)); + // HACK: insert self into recipients for DMs with users that no longer exist + else if (channel.type === ChannelType.DM) { + const selfUser = user.toPublicUser(); + users.add(selfUser); + channelUsers ??= []; + channelUsers.push(selfUser); + } + return { id: channel.id, flags: channel.flags,