MM-13897 preserve iOS push notifications when opening the app and set the proper badge count (#2541)

This commit is contained in:
Elias Nahum 2019-02-01 19:37:07 -03:00 committed by GitHub
parent 409d36d375
commit 2f997f631a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View file

@ -152,6 +152,8 @@ class PushNotification {
clearChannelNotifications(channelId) {
NotificationsIOS.getDeliveredNotifications((notifications) => {
const ids = [];
let badgeCount = notifications.length;
for (let i = 0; i < notifications.length; i++) {
const notification = notifications[i];
@ -161,8 +163,11 @@ class PushNotification {
}
if (ids.length) {
badgeCount -= ids.length;
NotificationsIOS.removeDeliveredNotifications(ids);
}
this.setApplicationIconBadgeNumber(badgeCount);
});
}
}

View file

@ -86,6 +86,10 @@ export default class Channel extends PureComponent {
} else {
this.props.actions.selectDefaultTeam();
}
if (this.props.currentChannelId) {
PushNotifications.clearChannelNotifications(this.props.currentChannelId);
}
}
componentDidMount() {

View file

@ -13,7 +13,6 @@ import {
import Icon from 'react-native-vector-icons/Ionicons';
import Badge from 'app/components/badge';
import PushNotifications from 'app/push_notifications';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import {preventDoubleTap} from 'app/utils/tap';
import {makeStyleSheetFromTheme} from 'app/utils/theme';
@ -61,10 +60,6 @@ class ChannelDrawerButton extends PureComponent {
EventEmitter.on('drawer_opacity', this.setOpacity);
}
componentDidUpdate() {
PushNotifications.setApplicationIconBadgeNumber(this.props.mentionCount);
}
componentWillUnmount() {
EventEmitter.off('drawer_opacity', this.setOpacity);
}

View file

@ -115,7 +115,7 @@ NSString* const NotificationClearAction = @"clear";
[self cleanNotificationsFromChannel:channelId andUpdateBadge:NO];
} else if (state == UIApplicationStateInactive) {
// When the notification is opened
[self cleanNotificationsFromChannel:channelId andUpdateBadge:YES];
[self cleanNotificationsFromChannel:channelId andUpdateBadge:NO];
}
[RNNotifications didReceiveRemoteNotification:userInfo];