feat : copy youtube studio
CI / Verify (push) Successful in 2m8s
CI / Build immutable images and deploy (push) Successful in 2m39s

This commit is contained in:
2026-10-08 03:26:00 +07:00 Unverified
parent 9bc710c94b
commit b665fe7497
16 changed files with 196 additions and 46 deletions
+8 -5
View File
@@ -8,9 +8,11 @@ import { pushPublicKey, validPushEndpoint } from "@/lib/commission/push";
import { createNotifications } from "@/lib/notifications/repository";
import { authorizeComment } from "./repository";
export async function sendCommentPush(id: string) {
export async function sendCommentPush(id: string, version?: number) {
const [reply] = await getDb().select().from(comments).where(eq(comments.id, id)).limit(1);
if (!reply || reply.hidden || reply.deletedAt) return;
const notificationVersion = version ?? reply.version;
const edited = notificationVersion > 1;
let recipients: { id: string; admin: boolean }[];
let url: string;
let title: string;
@@ -25,7 +27,7 @@ export async function sendCommentPush(id: string) {
} catch { return; }
recipients = [{ id: recipient.id, admin: false }];
url = `${destination.href}${destination.href.includes("?") ? "&" : "?"}reply=${id}#comment-${reply.rootId}`;
title = "ตอบกลับความคิดเห็นของคุณ";
title = edited ? "แก้ไขคำตอบกลับความคิดเห็นของคุณ" : "ตอบกลับความคิดเห็นของคุณ";
} else {
recipients = (await getDb().select({ id: users.id }).from(users)
.where(and(eq(users.role, "admin"), eq(users.emailVerified, true), ne(users.id, reply.authorId), sql`${users.banned} is not true`)))
@@ -37,15 +39,16 @@ export async function sendCommentPush(id: string) {
} catch { return; }
if (!destination.writable) return;
url = `/admin/comments?target=${encodeURIComponent(destination.target)}&comment=${id}`;
title = `แสดงความคิดเห็นใหม่ใน ${destination.name}`;
title = edited ? `แก้ไขความคิดเห็นใน ${destination.name}` : `แสดงความคิดเห็นใหม่ใน ${destination.name}`;
}
const [author] = await getDb().select({ name: users.name }).from(users).where(eq(users.id, reply.authorId)).limit(1);
const [revision] = await getDb().select({ text: commentRevisions.text }).from(commentRevisions)
.where(and(eq(commentRevisions.commentId, id), eq(commentRevisions.version, reply.version))).limit(1);
.where(and(eq(commentRevisions.commentId, id), eq(commentRevisions.version, notificationVersion))).limit(1);
if (!revision) return;
const notificationTitle = `${author?.name ?? "ผู้ใช้"} ${title}`;
const body = revision?.text.slice(0, 300) || "ส่งรูปภาพ";
await createNotifications(recipients.map(recipient => ({ userId: recipient.id, adminOnly: recipient.admin, url })), {
eventKey: `comment:${id}`, kind: reply.replyToId ? "comment_reply" : "comment_new", title: notificationTitle, body, commentId: id,
eventKey: edited ? `comment:${id}:edit:${notificationVersion}` : `comment:${id}`, kind: edited ? "comment_edit" : reply.replyToId ? "comment_reply" : "comment_new", title: notificationTitle, body, commentId: id,
});
if (!pushPublicKey()) return;
const subscriptions = await getDb().select().from(commentPushSubscriptions).where(inArray(commentPushSubscriptions.userId, recipients.map(recipient => recipient.id)));