fix: notifications and store styling

This commit is contained in:
DecDuck
2025-03-11 17:08:31 +11:00
parent 9515a21dc6
commit 137241fdbb
15 changed files with 203 additions and 81 deletions
+17 -7
View File
@@ -9,20 +9,29 @@ const socketSessions: { [key: string]: string } = {};
export default defineWebSocketHandler({
async open(peer) {
const userId = await aclManager.getUserIdACL(
{ headers: peer.request?.headers ?? new Headers() },
["notifications:listen"]
);
const h3 = { headers: peer.request?.headers ?? new Headers() };
const userId = await aclManager.getUserIdACL(h3, ["notifications:listen"]);
if (!userId) {
peer.send("unauthenticated");
return;
}
const userIds = [userId];
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
"notifications:listen",
]);
if (hasSystemPerms) {
userIds.push("system");
}
socketSessions[peer.id] = userId;
notificationSystem.listen(userId, peer.id, (notification) => {
peer.send(JSON.stringify(notification));
});
for (const listenUserId of userIds) {
notificationSystem.listen(listenUserId, peer.id, (notification) => {
peer.send(JSON.stringify(notification));
});
}
},
async close(peer, details) {
const userId = socketSessions[peer.id];
@@ -32,6 +41,7 @@ export default defineWebSocketHandler({
}
notificationSystem.unlisten(userId, peer.id);
notificationSystem.unlisten("system", peer.id); // In case we were listening as 'system'
delete socketSessions[peer.id];
},
});