diff options
Diffstat (limited to 'src/gateway/opcodes/PresenceUpdate.ts')
-rw-r--r-- | src/gateway/opcodes/PresenceUpdate.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/gateway/opcodes/PresenceUpdate.ts b/src/gateway/opcodes/PresenceUpdate.ts new file mode 100644 index 00000000..f31c9161 --- /dev/null +++ b/src/gateway/opcodes/PresenceUpdate.ts @@ -0,0 +1,24 @@ +import { WebSocket, Payload } from "@fosscord/gateway"; +import { ActivitySchema, emitEvent, PresenceUpdateEvent, Session, User } from "@fosscord/util"; +import { check } from "./instanceOf"; + +export async function onPresenceUpdate(this: WebSocket, { d }: Payload) { + check.call(this, ActivitySchema, d); + const presence = d as ActivitySchema; + + await Session.update( + { session_id: this.session_id }, + { status: presence.status, activities: presence.activities } + ); + + await emitEvent({ + event: "PRESENCE_UPDATE", + user_id: this.user_id, + data: { + user: await User.getPublicUser(this.user_id), + activities: presence.activities, + client_status: {}, // TODO: + status: presence.status, + }, + } as PresenceUpdateEvent); +} |