feat(notifications) : notify guide publications and admin hearts; simplify Stygian navigation
CI / Verify (push) Successful in 1m42s
CI / Build immutable images and deploy (push) Successful in 3m3s

This commit is contained in:
2026-10-08 04:04:02 +07:00 Unverified
parent b665fe7497
commit 72e9f525cc
8 changed files with 284 additions and 8 deletions
+18
View File
@@ -241,6 +241,24 @@ export async function mutateComment(id: string, viewer: CommentViewer, action: "
} else if (action === "heart") {
requireCommentAdmin(viewer);
await tx.update(comments).set({ heartedById: value ? viewer.id : null }).where(eq(comments.id, id));
if (value && !c.heartedById && c.authorId !== viewer.id) {
const [author] = await tx.select({ id: users.id, email: users.email, role: users.role, emailVerified: users.emailVerified, banned: users.banned })
.from(users).where(eq(users.id, c.authorId)).limit(1);
if (!author || author.banned) return;
let destination;
try {
({ destination } = await authorizeComment(id, { id: author.id, admin: isAuthorizedAdmin(author) }, tx));
} catch (cause) {
if (cause instanceof HttpError && cause.status === 404) return;
throw cause;
}
const url = `${destination.href}${c.rootId ? `${destination.href.includes("?") ? "&" : "?"}reply=${id}` : ""}#comment-${c.rootId ?? id}`;
notificationUsers = await tx.insert(notifications).values({
userId: author.id, eventKey: `comment:${id}:heart`, kind: "comment_heart",
title: "คุณได้รับหัวใจจากแอดมิน", body: `แอดมินให้หัวใจความคิดเห็นของคุณใน ${destination.name}`,
url, commentId: id,
}).onConflictDoNothing({ target: [notifications.userId, notifications.eventKey] }).returning({ userId: notifications.userId });
}
} else if (value === 0) {
await tx.delete(commentReactions).where(and(eq(commentReactions.commentId, id), eq(commentReactions.userId, viewer.id)));
} else {