mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
fix: notifications and store styling
This commit is contained in:
@ -12,10 +12,18 @@ export default defineEventHandler(async (h3) => {
|
||||
statusMessage: "Missing notification ID",
|
||||
});
|
||||
|
||||
const userIds = [userId];
|
||||
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
|
||||
"notifications:delete",
|
||||
]);
|
||||
if (hasSystemPerms) {
|
||||
userIds.push("system");
|
||||
}
|
||||
|
||||
const notification = await prisma.notification.delete({
|
||||
where: {
|
||||
id: notificationId,
|
||||
userId,
|
||||
userId: { in: userIds },
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -12,10 +12,18 @@ export default defineEventHandler(async (h3) => {
|
||||
statusMessage: "Missing notification ID",
|
||||
});
|
||||
|
||||
const userIds = [userId];
|
||||
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
|
||||
"notifications:read",
|
||||
]);
|
||||
if (hasSystemPerms) {
|
||||
userIds.push("system");
|
||||
}
|
||||
|
||||
const notification = await prisma.notification.findFirst({
|
||||
where: {
|
||||
id: notificationId,
|
||||
userId,
|
||||
userId: { in: userIds },
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -12,10 +12,18 @@ export default defineEventHandler(async (h3) => {
|
||||
statusMessage: "Missing notification ID",
|
||||
});
|
||||
|
||||
const userIds = [userId];
|
||||
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
|
||||
"notifications:mark",
|
||||
]);
|
||||
if (hasSystemPerms) {
|
||||
userIds.push("system");
|
||||
}
|
||||
|
||||
const notification = await prisma.notification.update({
|
||||
where: {
|
||||
id: notificationId,
|
||||
userId,
|
||||
userId: { in: userIds },
|
||||
},
|
||||
data: {
|
||||
read: true,
|
||||
|
||||
@ -5,9 +5,17 @@ export default defineEventHandler(async (h3) => {
|
||||
const userId = await aclManager.getUserIdACL(h3, ["notifications:read"]);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const userIds = [userId];
|
||||
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
|
||||
"notifications:mark",
|
||||
]);
|
||||
if (hasSystemPerms) {
|
||||
userIds.push("system");
|
||||
}
|
||||
|
||||
const notifications = await prisma.notification.findMany({
|
||||
where: {
|
||||
userId,
|
||||
userId: { in: userIds },
|
||||
},
|
||||
orderBy: {
|
||||
created: "desc", // Newest first
|
||||
|
||||
@ -5,9 +5,17 @@ export default defineEventHandler(async (h3) => {
|
||||
const userId = await aclManager.getUserIdACL(h3, ["notifications:mark"]);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const userIds = [userId];
|
||||
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
|
||||
"notifications:mark",
|
||||
]);
|
||||
if(hasSystemPerms){
|
||||
userIds.push("system");
|
||||
}
|
||||
|
||||
await prisma.notification.updateMany({
|
||||
where: {
|
||||
userId,
|
||||
userId: { in: userIds },
|
||||
},
|
||||
data: {
|
||||
read: true,
|
||||
|
||||
@ -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