summary refs log tree commit diff
path: root/src/gateway/opcodes/GuildSync.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/gateway/opcodes/GuildSync.ts')
-rw-r--r--src/gateway/opcodes/GuildSync.ts18
1 files changed, 1 insertions, 17 deletions
diff --git a/src/gateway/opcodes/GuildSync.ts b/src/gateway/opcodes/GuildSync.ts

index 770e62c8..34bfdb90 100644 --- a/src/gateway/opcodes/GuildSync.ts +++ b/src/gateway/opcodes/GuildSync.ts
@@ -32,7 +32,7 @@ import { Stopwatch, Guild, } from "@spacebar/util"; -import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send } from "@spacebar/gateway"; +import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send, getMostRelevantSession } from "@spacebar/gateway"; import murmur from "murmurhash-js/murmurhash3_gc"; import { check } from "./instanceOf"; import { LazyRequestSchema, PublicMember } from "@spacebar/schemas"; @@ -42,22 +42,6 @@ import { In } from "typeorm"; // TODO: config: to list all members (even those who are offline) sorted by role, or just those who are online // TODO: rewrite typeorm -const getMostRelevantSession = (sessions: Session[]) => { - const statusMap = { - online: 0, - idle: 1, - dnd: 2, - invisible: 3, - offline: 4, - }; - // sort sessions by relevance - sessions = sessions.sort((a, b) => { - return statusMap[a.status] - statusMap[b.status] + ((a.activities?.length ?? 0) - (b.activities?.length ?? 0)) * 2; - }); - - return sessions[0]; -}; - export async function onGuildSync(this: WebSocket, { d }: Payload) { const sw = Stopwatch.startNew(); if (!Array.isArray(d)) throw new Error("Invalid payload for GUILD_SYNC");