mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 01:34:38 +10:00
fix: notifications and store styling
This commit is contained in:
@@ -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];
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user