fix(comments) : show notified threads in inbox and stop edit notifications
This commit is contained in:
@@ -570,7 +570,7 @@ describeDatabase("guide comments against PostgreSQL", { timeout: 30000 }, () =>
|
||||
expect(notifyNotificationChange).toHaveBeenCalledWith(admin.id);
|
||||
expect((await listNotifications(adminUser)).items).toHaveLength(0);
|
||||
}, 60000);
|
||||
it("notifies admins for each saved edit without duplicating the same revision", async () => {
|
||||
it("saves comment edits without notifying admins", async () => {
|
||||
const root = await post("Original");
|
||||
const adminUser = { ...admin, role: "admin", emailVerified: true };
|
||||
await sendCommentPush(root.id, 1);
|
||||
@@ -579,22 +579,19 @@ describeDatabase("guide comments against PostgreSQL", { timeout: 30000 }, () =>
|
||||
const response = await itemRoute.PATCH(request("Edited with image", { version: 1, images: [png] }), { params: Promise.resolve({ id: root.id }) });
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toMatchObject({ id: root.id, version: 2 });
|
||||
expect(after).toHaveBeenCalledTimes(1);
|
||||
const task = vi.mocked(after).mock.calls[0][0];
|
||||
if (typeof task !== "function") throw new Error("Expected scheduled notification callback");
|
||||
await task();
|
||||
await task();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
await sendCommentPush(root.id, 2);
|
||||
const feed = await listNotifications(adminUser);
|
||||
expect(feed.unread).toBe(1);
|
||||
expect(feed.items[0]).toMatchObject({ kind: "comment_edit", eventKey: `comment:${root.id}:edit:2`, body: "Edited with image", readAt: null });
|
||||
expect(feed.unread).toBe(0);
|
||||
expect(feed.items).toHaveLength(1);
|
||||
expect(feed.items[0]).toMatchObject({ kind: "comment_new", eventKey: `comment:${root.id}`, body: "Original" });
|
||||
await publishComment(request("Third revision", { version: 2 }), author, { id: root.id });
|
||||
await sendCommentPush(root.id, 3);
|
||||
expect((await listNotifications(adminUser)).unread).toBe(2);
|
||||
// A delayed notification must use the revision that triggered it.
|
||||
expect((await listNotifications(adminUser)).unread).toBe(0);
|
||||
await sendCommentPush(root.id, 2);
|
||||
expect((await listNotifications(adminUser)).unread).toBe(2);
|
||||
expect((await listNotifications(adminUser)).items).toHaveLength(1);
|
||||
});
|
||||
it("notifies the direct recipient of edited replies and suppresses hidden edits", async () => {
|
||||
it("does not notify the direct recipient of edited replies", async () => {
|
||||
await saveSubscription(author.id);
|
||||
const root = await post("Root");
|
||||
const reply = await publishComment(request("Reply", { reply: root.id }), other, { target });
|
||||
@@ -603,11 +600,12 @@ describeDatabase("guide comments against PostgreSQL", { timeout: 30000 }, () =>
|
||||
pushTransport.sendNotification.mockClear();
|
||||
await publishComment(request("Edited reply", { version: 1, images: [png] }), other, { id: reply.id });
|
||||
await sendCommentPush(reply.id, 2);
|
||||
expect(pushTransport.sendNotification).toHaveBeenCalledTimes(1);
|
||||
expect(JSON.parse(pushTransport.sendNotification.mock.calls[0][1])).toMatchObject({ body: "Edited reply", title: "Reader แก้ไขคำตอบกลับความคิดเห็นของคุณ" });
|
||||
await sendCommentPush(reply.id);
|
||||
expect(pushTransport.sendNotification).not.toHaveBeenCalled();
|
||||
const feed = await listNotifications({ ...author, role: "user", emailVerified: true });
|
||||
expect(feed.unread).toBe(1);
|
||||
expect(feed.items[0]).toMatchObject({ kind: "comment_edit", body: "Edited reply" });
|
||||
expect(feed.unread).toBe(0);
|
||||
expect(feed.items).toHaveLength(1);
|
||||
expect(feed.items[0]).toMatchObject({ kind: "comment_reply", body: "Reply" });
|
||||
expect(feed.items[0].url).toContain(`reply=${reply.id}#comment-${root.id}`);
|
||||
await publishComment(request("Hidden revision", { version: 2 }), other, { id: reply.id });
|
||||
await mutateComment(root.id, admin, "moderation", true);
|
||||
|
||||
Reference in New Issue
Block a user