username update, status message update, status overwriting, global

status in client
This commit is contained in:
Soph :3 2026-01-13 00:20:10 +02:00
parent 9ffb3cf283
commit d9f5919b60
11 changed files with 235 additions and 79 deletions

View file

@ -22,7 +22,7 @@ export function _sendToSubscribers(id: string, payload: unknown) {
}
}
export function _sendToUser(userId: string, payload: unknown) {
for (const [_, client] of _clients) {
for (const [, client] of _clients) {
if (client.userId == userId) {
client.controller.enqueue(`data: ${JSON.stringify(payload)}\n\n`);
}
@ -59,10 +59,15 @@ export async function GET({ locals, request }) {
if (overwrite === Status.DND) {
kvStore.set(`user-${userId}-state`, Status.DND);
_sendToSubscribers(userId, { type: 'status', id: userId, status: Status.DND });
} else {
kvStore.set(`user-${userId}-state`, Status.ONLINE);
_sendToSubscribers(userId, { type: 'status', id: userId, status: Status.ONLINE });
_sendToSubscribers(userId, {
type: 'status',
id: userId,
status: Status.DND,
statusMessage:
kvStore.get('user-' + userId + '-state') != Status.OFFLINE
? kvStore.get('user-' + userId + '-message')
: ''
});
}
request.signal.addEventListener('abort', () => {
@ -74,7 +79,12 @@ export async function GET({ locals, request }) {
if (overwrite === Status.OFFLINE) return;
kvStore.set(`user-${userId}-state`, Status.OFFLINE);
_sendToSubscribers(userId, { type: 'status', id: userId, status: Status.OFFLINE });
_sendToSubscribers(userId, {
type: 'status',
id: userId,
status: Status.OFFLINE,
statusMessage: ''
});
});
},
cancel() {
@ -85,7 +95,12 @@ export async function GET({ locals, request }) {
if (overwrite === Status.OFFLINE) return;
kvStore.set(`user-${userId}-state`, Status.OFFLINE);
_sendToSubscribers(userId, { type: 'status', id: userId, status: Status.OFFLINE });
_sendToSubscribers(userId, {
type: 'status',
id: userId,
status: Status.OFFLINE,
statusMessage: ''
});
}
});