diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts index 02d171fe8..96eac986f 100644 --- a/src/gateway/listener/listener.ts +++ b/src/gateway/listener/listener.ts @@ -106,6 +106,7 @@ export async function setupListener(this: WebSocket) { } this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts); + this.events[this.session_id] = await listenEvent(this.session_id, consumer, opts); await Promise.all( relationships.map(async (relationship) => { diff --git a/src/util/interfaces/Event.ts b/src/util/interfaces/Event.ts index 5a039e9bb..6971a61a1 100644 --- a/src/util/interfaces/Event.ts +++ b/src/util/interfaces/Event.ts @@ -36,6 +36,7 @@ import { ReadyPrivateChannel, GuildOrUnavailable, Snowflake, + ThreadMember, } from "@spacebar/util"; import { JsonValue } from "@protobuf-ts/runtime"; import { @@ -49,11 +50,11 @@ import { RelationshipType, UserPrivate, } from "@spacebar/schemas"; -import { ThreadMember } from "../entities/ThreadMember"; export interface Event { guild_id?: string; user_id?: string; + session_id?: string; channel_id?: string; created_at?: Date; event: EVENT; diff --git a/src/util/util/Event.ts b/src/util/util/Event.ts index 2e6cf8206..78f487b8c 100644 --- a/src/util/util/Event.ts +++ b/src/util/util/Event.ts @@ -35,7 +35,7 @@ let unixSocketListener: UnixSocketListener | null = null; let unixSocketWriter: UnixSocketWriter | null = null; export async function emitEvent(payload: Omit) { - const id = (payload.guild_id || payload.channel_id || payload.user_id) as string; + const id = (payload.guild_id || payload.channel_id || payload.user_id || payload.session_id) as string; if (!id) return console.error("event doesn't contain any id", payload); if (RabbitMQ.connection) { @@ -485,7 +485,7 @@ class UnixSocketWriter { await this.broadcastLock; return await (this.broadcastLock = new Promise((res) => { const tsw = Stopwatch.startNew(); - const payloadBuf = Buffer.from(JSON.stringify({ id: (event.guild_id || event.channel_id || event.user_id) as string, event })); + const payloadBuf = Buffer.from(JSON.stringify({ id: (event.guild_id || event.channel_id || event.user_id || event.session_id) as string, event })); const lenBuf = Buffer.alloc(4); lenBuf.writeUInt32BE(payloadBuf.length, 0); const framed = Buffer.concat([lenBuf, payloadBuf]);