Skip to content

Commit 38ac3b2

Browse files
committed
feat(notifications): Add extra filter to normaliser to return only unread notifications
Discourse doesn't provide a way to ask only for unread notifications, instead, it provides a way to know if there is unread notifications and then pull the recent ones which lead to the need to having a way to further filter those notifications to show only unread ones after get all
1 parent 1da6b6f commit 38ac3b2

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/notifications/__tests__/normaliser.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@ describe("normaliser", () => {
1010
expect(result.alerts).toEqual([notifications[1], notifications[3]]);
1111
expect(result.messages).toEqual([notifications[0], notifications[2]]);
1212
});
13+
14+
it("returns only unread notifications", () => {
15+
const notificationsUpdated = [...notifications];
16+
notificationsUpdated[3].read = true;
17+
notificationsUpdated[2].read = true;
18+
const result = normaliseUserNotifications(notificationsUpdated);
19+
20+
expect(result.alerts).toEqual([notifications[1]]);
21+
expect(result.messages).toEqual([notifications[0]]);
22+
});
1323
});

src/notifications/normaliser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// @flow
22

3+
import filter from "lodash/filter";
34
import includes from "lodash/includes";
45
import { notificationTypes } from "./helpers";
56

67
const getMessages = notifications => {
78
const messagesTypes = [notificationTypes[5], notificationTypes[6]];
89

9-
return notifications.filter(
10-
n => messagesTypes.indexOf(notificationTypes[n.notification_type]) > -1
10+
return filter(
11+
notifications,
12+
(n: Notification) =>
13+
messagesTypes.indexOf(notificationTypes[n.notification_type]) > -1
1114
);
1215
};
1316

@@ -18,7 +21,7 @@ export const normaliseUserNotifications = (
1821
const alerts = notifications.filter(n => !includes(messages, n));
1922

2023
return {
21-
alerts,
22-
messages,
24+
alerts: filter(alerts, { read: false }),
25+
messages: filter(messages, { read: false }),
2326
};
2427
};

0 commit comments

Comments
 (0)