Do not track foreground notifications when notification is opened (#3111)

This commit is contained in:
Mattermost Build
2019-08-13 16:18:55 +02:00
committed by Elias Nahum
parent e3fd88b7fb
commit 390c30af00
2 changed files with 15 additions and 2 deletions

View File

@@ -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) => {

View File

@@ -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();
});
});
});