feat: Archive all notifications (#6599)
* feat: Archive all notifications * use non-modal notification menu * don't show icons in context menu
This commit is contained in:
@@ -34,6 +34,7 @@ describe("#notifications.list", () => {
|
||||
event: NotificationEventType.UpdateDocument,
|
||||
userId: user.id,
|
||||
viewedAt: new Date(),
|
||||
archivedAt: new Date(),
|
||||
}),
|
||||
buildNotification({
|
||||
actorId: actor.id,
|
||||
@@ -196,6 +197,68 @@ describe("#notifications.list", () => {
|
||||
expect(events).toContain(NotificationEventType.CreateComment);
|
||||
expect(events).toContain(NotificationEventType.UpdateDocument);
|
||||
});
|
||||
|
||||
it("should return non-archived notifications", async () => {
|
||||
const actor = await buildUser();
|
||||
const user = await buildUser({
|
||||
teamId: actor.teamId,
|
||||
});
|
||||
const collection = await buildCollection({
|
||||
teamId: actor.teamId,
|
||||
createdById: actor.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: actor.teamId,
|
||||
createdById: actor.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await Promise.all([
|
||||
buildNotification({
|
||||
actorId: actor.id,
|
||||
documentId: document.id,
|
||||
collectionId: collection.id,
|
||||
event: NotificationEventType.UpdateDocument,
|
||||
archivedAt: new Date(),
|
||||
userId: user.id,
|
||||
}),
|
||||
buildNotification({
|
||||
actorId: actor.id,
|
||||
documentId: document.id,
|
||||
collectionId: collection.id,
|
||||
event: NotificationEventType.CreateComment,
|
||||
archivedAt: new Date(),
|
||||
userId: user.id,
|
||||
}),
|
||||
buildNotification({
|
||||
actorId: actor.id,
|
||||
documentId: document.id,
|
||||
collectionId: collection.id,
|
||||
event: NotificationEventType.MentionedInComment,
|
||||
userId: user.id,
|
||||
}),
|
||||
]);
|
||||
|
||||
const res = await server.post("/api/notifications.list", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
archived: false,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(body.data.notifications.length).toBe(1);
|
||||
expect(body.pagination.total).toBe(1);
|
||||
expect(body.data.unseen).toBe(1);
|
||||
expect((randomElement(body.data.notifications) as any).actor.id).toBe(
|
||||
actor.id
|
||||
);
|
||||
expect((randomElement(body.data.notifications) as any).userId).toBe(
|
||||
user.id
|
||||
);
|
||||
const events = body.data.notifications.map((n: any) => n.event);
|
||||
expect(events).toContain(NotificationEventType.MentionedInComment);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#notifications.update", () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Router from "koa-router";
|
||||
import { isNil } from "lodash";
|
||||
import isNull from "lodash/isNull";
|
||||
import isUndefined from "lodash/isUndefined";
|
||||
import { WhereOptions, Op } from "sequelize";
|
||||
@@ -80,12 +81,16 @@ router.post(
|
||||
if (eventType) {
|
||||
where = { ...where, event: eventType };
|
||||
}
|
||||
if (archived) {
|
||||
if (!isNil(archived)) {
|
||||
where = {
|
||||
...where,
|
||||
archivedAt: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
archivedAt: archived
|
||||
? {
|
||||
[Op.ne]: null,
|
||||
}
|
||||
: {
|
||||
[Op.eq]: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
const [notifications, total, unseen] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user