From 72de959221b44eb3d3533fd5624957cb1d29f058 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 6 Jun 2017 15:54:08 +0200 Subject: [PATCH] Remove notifications for deleted messages. --- src/modules/statuses.js | 4 ++++ test/unit/specs/modules/statuses.spec.js | 28 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 051ec71b..98a8d16d 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -242,6 +242,10 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const uri = deletion.uri updateMaxId(deletion) + // Remove possible notification + const status = find(allStatuses, {uri}) + remove(state.notifications, ({action: {id}}) => status.id) + remove(allStatuses, { uri }) if (timeline) { remove(timelineObject.statuses, { uri }) diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index 891423ca..66d6cfd7 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -319,6 +319,34 @@ describe('The Statuses module', () => { expect(state.notifications[0].type).to.eql('mention') }) + it('removes a notification when the notice gets removed', () => { + const user = { id: 1 } + const state = cloneDeep(defaultState) + const status = makeMockStatus({id: 1}) + const mentionedStatus = makeMockStatus({id: 2}) + mentionedStatus.attentions = [user] + mentionedStatus.uri = 'xxx' + + const deletion = makeMockStatus({id: 3, is_post_verb: false}) + deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.' + deletion.uri = 'xxx' + + mutations.addNewStatuses(state, { statuses: [status], user }) + + expect(state.notifications.length).to.eql(0) + + mutations.addNewStatuses(state, { statuses: [mentionedStatus], user }) + expect(state.allStatuses.length).to.eql(2) + expect(state.notifications.length).to.eql(1) + expect(state.notifications[0].status).to.eql(mentionedStatus) + expect(state.notifications[0].action).to.eql(mentionedStatus) + expect(state.notifications[0].type).to.eql('mention') + + mutations.addNewStatuses(state, { statuses: [deletion], user }) + expect(state.allStatuses.length).to.eql(1) + expect(state.notifications.length).to.eql(0) + }) + it('adds the message to mentions when you are mentioned', () => { const user = { id: 1 } const state = cloneDeep(defaultState)