summary refs log tree commit diff
path: root/src/gateway/opcodes/PresenceUpdate.ts
blob: ad71223490c7410541ddd55f59eb618a9298961b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { Payload, WebSocket } 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);
}