diff --git a/gateway/src/events/Close.ts b/gateway/src/events/Close.ts
index 5c1bd292..5b7c512c 100644
--- a/gateway/src/events/Close.ts
+++ b/gateway/src/events/Close.ts
@@ -1,13 +1,46 @@
import { WebSocket } from "@fosscord/gateway";
-import { Session } from "@fosscord/util";
+import {
+ emitEvent,
+ PresenceUpdateEvent,
+ PrivateSessionProjection,
+ Session,
+ SessionsReplace,
+ User,
+} from "@fosscord/util";
export async function Close(this: WebSocket, code: number, reason: string) {
console.log("[WebSocket] closed", code, reason);
- if (this.session_id) await Session.delete({ session_id: this.session_id });
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
if (this.readyTimeout) clearTimeout(this.readyTimeout);
-
this.deflate?.close();
-
this.removeAllListeners();
+
+ if (this.session_id) {
+ await Session.delete({ session_id: this.session_id });
+ const sessions = await Session.find({
+ where: { user_id: this.user_id },
+ select: PrivateSessionProjection,
+ });
+ await emitEvent({
+ event: "SESSIONS_REPLACE",
+ user_id: this.user_id,
+ data: sessions,
+ } as SessionsReplace);
+ const session = sessions.first() || {
+ activities: [],
+ client_info: {},
+ status: "offline",
+ };
+
+ await emitEvent({
+ event: "PRESENCE_UPDATE",
+ user_id: this.user_id,
+ data: {
+ user: await User.getPublicUser(this.user_id),
+ activities: session.activities,
+ client_status: session?.client_info,
+ status: session.status,
+ },
+ } as PresenceUpdateEvent);
+ }
}
diff --git a/gateway/src/events/Connection.ts b/gateway/src/events/Connection.ts
index 9bb034f0..4954cd08 100644
--- a/gateway/src/events/Connection.ts
+++ b/gateway/src/events/Connection.ts
@@ -8,7 +8,6 @@ import { Close } from "./Close";
import { Message } from "./Message";
import { createDeflate } from "zlib";
import { URL } from "url";
-import { Session } from "@fosscord/util";
var erlpack: any;
try {
erlpack = require("@yukikaze-bot/erlpack");
@@ -57,6 +56,7 @@ export async function Connection(
}
socket.events = {};
+ socket.member_events = {};
socket.permissions = {};
socket.sequence = 0;
|