feat(notifications) : notify guide publications and admin hearts; simplify Stygian navigation
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user