From 9cdeba0df58f1be988c2a8fbcc2de6edff1ec76c Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Wed, 13 Nov 2019 23:42:50 +0900
Subject: [PATCH] refs #1096 Reject duplicated status when append statuses in
Notifications
---
.../Contents/Notifications.spec.ts | 73 +++++++++++++++++++
.../TimelineSpace/Contents/Notifications.ts | 14 +++-
2 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts
index 6a7531ab..99f54e36 100644
--- a/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts
+++ b/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts
@@ -184,5 +184,78 @@ describe('TimelineSpace/Contents/Notifications', () => {
})
})
})
+
+ describe('appendTimeline', () => {
+ describe('heading', () => {
+ describe('normal', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: true,
+ notifications: [notification1],
+ unreadNotifications: [],
+ filter: ''
+ }
+ })
+ it('should update timeline', () => {
+ Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
+ expect(state.notifications).toEqual([notification2, notification1])
+ expect(state.unreadNotifications).toEqual([])
+ })
+ })
+
+ describe('duplicated status', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: true,
+ notifications: [notification2, notification1],
+ unreadNotifications: [],
+ filter: ''
+ }
+ })
+ it('should not update timeline', () => {
+ Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
+ expect(state.notifications).toEqual([notification2, notification1])
+ expect(state.unreadNotifications).toEqual([])
+ })
+ })
+ })
+
+ describe('not heading', () => {
+ describe('normal', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: false,
+ notifications: [notification1],
+ unreadNotifications: [],
+ filter: ''
+ }
+ })
+ it('should update unreadTimeline', () => {
+ Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
+ expect(state.notifications).toEqual([notification1])
+ expect(state.unreadNotifications).toEqual([notification2])
+ })
+ })
+ describe('duplicated status', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: false,
+ notifications: [notification1],
+ unreadNotifications: [notification2],
+ filter: ''
+ }
+ })
+ it('should not update unreadTimeline', () => {
+ Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
+ expect(state.notifications).toEqual([notification1])
+ expect(state.unreadNotifications).toEqual([notification2])
+ })
+ })
+ })
+ })
})
})
diff --git a/src/renderer/store/TimelineSpace/Contents/Notifications.ts b/src/renderer/store/TimelineSpace/Contents/Notifications.ts
index 1225b95e..2e245bbd 100644
--- a/src/renderer/store/TimelineSpace/Contents/Notifications.ts
+++ b/src/renderer/store/TimelineSpace/Contents/Notifications.ts
@@ -41,10 +41,16 @@ const mutations: MutationTree = {
state.heading = value
},
[MUTATION_TYPES.APPEND_NOTIFICATIONS]: (state, notification: Notification) => {
- if (state.heading) {
- state.notifications = [notification].concat(state.notifications)
- } else {
- state.unreadNotifications = [notification].concat(state.unreadNotifications)
+ // Reject duplicated status in timeline
+ if (
+ !state.notifications.find(item => item.id === notification.id) &&
+ !state.unreadNotifications.find(item => item.id === notification.id)
+ ) {
+ if (state.heading) {
+ state.notifications = [notification].concat(state.notifications)
+ } else {
+ state.unreadNotifications = [notification].concat(state.unreadNotifications)
+ }
}
},
[MUTATION_TYPES.UPDATE_NOTIFICATIONS]: (state, notifications: Array) => {