1616 along with this program. If not, see <https://www.gnu.org/licenses/>.
1717*/
1818
19- import { CLOSECODES , Capabilities , OPCODES , Payload , Send , WebSocket , setupListener } from "@spacebar/gateway" ;
19+ import { Capabilities , CLOSECODES , OPCODES , Payload , Send , setupListener , WebSocket } from "@spacebar/gateway" ;
2020import {
2121 Application ,
22+ Channel ,
23+ checkToken ,
2224 Config ,
25+ CurrentTokenFormatVersion ,
26+ ElapsedTime ,
27+ emitEvent ,
28+ Emoji ,
2329 EVENTEnum ,
30+ generateToken ,
31+ getDatabase ,
2432 Guild ,
2533 GuildOrUnavailable ,
2634 Intents ,
@@ -33,32 +41,24 @@ import {
3341 ReadyGuildDTO ,
3442 ReadyUserGuildSettingsEntries ,
3543 Recipient ,
44+ Relationship ,
45+ Role ,
3646 Session ,
3747 SessionsReplace ,
38- UserSettings ,
39- checkToken ,
40- emitEvent ,
41- getDatabase ,
42- TraceNode ,
43- TraceRoot ,
48+ Sticker ,
4449 Stopwatch ,
50+ timeFunction ,
4551 timePromise ,
46- ElapsedTime ,
47- Channel ,
48- Emoji ,
49- Role ,
50- Sticker ,
51- VoiceState ,
52+ TraceNode ,
53+ TraceRoot ,
54+ UserSettings ,
5255 UserSettingsProtos ,
53- generateToken ,
54- CurrentTokenFormatVersion ,
55- Relationship ,
56- timeFunction ,
56+ VoiceState ,
5757} from "@spacebar/util" ;
5858import { check } from "./instanceOf" ;
5959import { In , Not } from "typeorm" ;
6060import { PreloadedUserSettings } from "discord-protos" ;
61- import { DefaultUserGuildSettings , DMChannel , IdentifySchema , PrivateUserProjection , PublicUser , PublicUserProjection } from "@spacebar/schemas" ;
61+ import { ChannelType , DefaultUserGuildSettings , DMChannel , IdentifySchema , PrivateUserProjection , PublicUser , PublicUserProjection } from "@spacebar/schemas" ;
6262
6363// TODO: user sharding
6464// TODO: check privileged intents, if defined in the config
@@ -479,9 +479,17 @@ export async function onIdentify(this: WebSocket, data: Payload) {
479479 // Remove ourself from the list of other users in dm channel
480480 channel . recipients = channel . recipients . filter ( ( recipient ) => recipient . user . id !== this . user_id ) ;
481481
482- const channelUsers = channel . recipients ?. map ( ( recipient ) => recipient . user . toPublicUser ( ) ) ;
482+ let channelUsers = channel . recipients ?. map ( ( recipient ) => recipient . user . toPublicUser ( ) ) ;
483483
484484 if ( channelUsers && channelUsers . length > 0 ) channelUsers . forEach ( ( user ) => users . add ( user ) ) ;
485+ // HACK: insert self into recipients for DMs with users that no longer exist
486+ else if ( channel . type === ChannelType . DM ) {
487+ const selfUser = user . toPublicUser ( ) ;
488+ users . add ( selfUser ) ;
489+ channelUsers ??= [ ] ;
490+ channelUsers . push ( selfUser ) ;
491+ }
492+
485493 return {
486494 id : channel . id ,
487495 flags : channel . flags ,
0 commit comments