From 390c30af009e7f49890b229693e5d429ff280692 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Tue, 13 Aug 2019 16:18:55 +0200 Subject: [PATCH] Do not track foreground notifications when notification is opened (#3111) --- app/push_notifications/push_notifications.ios.js | 4 +++- .../push_notifications.ios.test.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/push_notifications/push_notifications.ios.js b/app/push_notifications/push_notifications.ios.js index 1040e3ca0..3aa56756d 100644 --- a/app/push_notifications/push_notifications.ios.js +++ b/app/push_notifications/push_notifications.ios.js @@ -54,7 +54,9 @@ class PushNotification { this.onNotification(this.deviceNotification); } - this.trackForegroundNotification(data.channel_id); + if (foreground) { + this.trackForegroundNotification(data.channel_id); + } }; handleReply = (action, completed) => { diff --git a/app/push_notifications/push_notifications.ios.test.js b/app/push_notifications/push_notifications.ios.test.js index 88e5b5e32..0dda9a7fa 100644 --- a/app/push_notifications/push_notifications.ios.test.js +++ b/app/push_notifications/push_notifications.ios.test.js @@ -59,6 +59,17 @@ describe('PushNotification', () => { expect(foregroundNotifications[channel2ID]).toBe(undefined); }); + it('should NOT track foreground notifications for channel when opened', async () => { + let item = await AsyncStorage.getItem(FOREGROUND_NOTIFICATIONS_KEY); + expect(item).toBe(null); + + PushNotification.trackForegroundNotification = jest.fn(); + PushNotification.onNotificationOpened(notification); + expect(PushNotification.trackForegroundNotification).not.toBeCalled(); + item = await AsyncStorage.getItem(FOREGROUND_NOTIFICATIONS_KEY); + expect(item).toBe(null); + }); + it('should increment badge number when foreground notification is received', () => { const setApplicationIconBadgeNumber = jest.spyOn(PushNotification, 'setApplicationIconBadgeNumber'); @@ -150,4 +161,4 @@ describe('PushNotification', () => { expect(NotificationsIOS.cancelAllLocalNotifications).toHaveBeenCalled(); expect(clearForegroundNotifications).toHaveBeenCalled(); }); -}); \ No newline at end of file +});