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 +});