✨ User presence/status

This commit is contained in:
Flam3rboy
2021-10-17 00:39:54 +02:00
parent 116e17f6d0
commit 68053418f3
9 changed files with 193 additions and 50 deletions
+37 -4
View File
@@ -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);
}
}
+1 -1
View File
@@ -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;