summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-01-23 11:35:11 +0100
committerRory& <root@rory.gay>2026-01-23 11:35:11 +0100
commit0ed83c0b6c10a2ee9b6fbf684e557922b8160381 (patch)
treeeb22fb5066ad1c0a0615ea6a863ff2cc1b4fdd23
parentDummy warp endpoint (diff)
downloadserver-ts-0ed83c0b6c10a2ee9b6fbf684e557922b8160381.tar.xz
Identify: add self as recipient for DMs with nonexistnt users
-rw-r--r--src/gateway/opcodes/Identify.ts46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts

index d6f14627..34732c38 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -16,11 +16,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -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, - TraceNode, - TraceRoot, + Sticker, Stopwatch, + timeFunction, timePromise, - ElapsedTime, - Channel, - Emoji, - Role, - Sticker, - VoiceState, + TraceNode, + TraceRoot, + 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,