Fix regression opening a channel from a push notification (#2952)
This commit is contained in:
parent
ca72c5959b
commit
24f33b2f97
4 changed files with 68 additions and 49 deletions
|
|
@ -378,7 +378,7 @@ export function handleSelectChannel(channelId, fromPushNotification = false) {
|
|||
dispatch(loadPostsIfNecessaryWithRetry(channelId));
|
||||
}
|
||||
|
||||
dispatch(batchActions([
|
||||
const actions = [
|
||||
selectChannel(channelId),
|
||||
setChannelDisplayName(channel.display_name),
|
||||
{
|
||||
|
|
@ -391,19 +391,30 @@ export function handleSelectChannel(channelId, fromPushNotification = false) {
|
|||
teamId: currentTeamId,
|
||||
channelId,
|
||||
},
|
||||
{
|
||||
type: ViewTypes.SELECT_CHANNEL_WITH_MEMBER,
|
||||
data: channelId,
|
||||
channel,
|
||||
member,
|
||||
},
|
||||
]));
|
||||
];
|
||||
|
||||
let markPreviousChannelId;
|
||||
if (!fromPushNotification && !sameChannel) {
|
||||
markPreviousChannelId = currentChannelId;
|
||||
actions.push({
|
||||
type: ViewTypes.SELECT_CHANNEL_WITH_MEMBER,
|
||||
data: currentChannelId,
|
||||
channel: getChannel(state, currentChannelId),
|
||||
member: getMyChannelMember(state, currentChannelId),
|
||||
});
|
||||
}
|
||||
|
||||
if (!fromPushNotification) {
|
||||
actions.push({
|
||||
type: ViewTypes.SELECT_CHANNEL_WITH_MEMBER,
|
||||
data: channelId,
|
||||
channel,
|
||||
member,
|
||||
});
|
||||
}
|
||||
|
||||
dispatch(batchActions(actions));
|
||||
|
||||
dispatch(markChannelViewedAndRead(channelId, markPreviousChannelId));
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
import {AppState, NativeModules} from 'react-native';
|
||||
import {NotificationsAndroid, PendingNotifications} from 'react-native-notifications';
|
||||
|
||||
import ephemeralStore from 'app/store/ephemeral_store';
|
||||
|
||||
const {NotificationPreferences} = NativeModules;
|
||||
|
||||
class PushNotification {
|
||||
|
|
@ -65,6 +67,7 @@ class PushNotification {
|
|||
if (notification) {
|
||||
const data = notification.getData();
|
||||
if (data) {
|
||||
ephemeralStore.appStartedFromPushNotification = true;
|
||||
this.handleNotification(data, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
import {AppState} from 'react-native';
|
||||
import NotificationsIOS, {NotificationAction, NotificationCategory} from 'react-native-notifications';
|
||||
|
||||
import ephemeralStore from 'app/store/ephemeral_store';
|
||||
|
||||
const CATEGORY = 'CAN_REPLY';
|
||||
const REPLY_ACTION = 'REPLY_ACTION';
|
||||
|
||||
|
|
@ -17,29 +19,10 @@ class PushNotification {
|
|||
this.onNotification = null;
|
||||
this.onReply = null;
|
||||
|
||||
NotificationsIOS.addEventListener('notificationReceivedForeground', (notification) => {
|
||||
const info = {
|
||||
...notification.getData(),
|
||||
message: notification.getMessage(),
|
||||
};
|
||||
this.handleNotification(info, true, false);
|
||||
});
|
||||
|
||||
NotificationsIOS.addEventListener('notificationReceivedBackground', (notification) => {
|
||||
const info = {
|
||||
...notification.getData(),
|
||||
message: notification.getMessage(),
|
||||
};
|
||||
this.handleNotification(info, false, false);
|
||||
});
|
||||
|
||||
NotificationsIOS.addEventListener('notificationOpened', (notification) => {
|
||||
const info = {
|
||||
...notification.getData(),
|
||||
message: notification.getMessage(),
|
||||
};
|
||||
this.handleNotification(info, false, true);
|
||||
});
|
||||
NotificationsIOS.addEventListener('remoteNotificationsRegistered', this.onRemoteNotificationsRegistered);
|
||||
NotificationsIOS.addEventListener('notificationReceivedForeground', this.onNotificationReceivedForeground);
|
||||
NotificationsIOS.addEventListener('notificationReceivedBackground', this.onNotificationReceivedBackground);
|
||||
NotificationsIOS.addEventListener('notificationOpened', this.onNotificationOpened);
|
||||
|
||||
const replyAction = new NotificationAction({
|
||||
activationMode: 'background',
|
||||
|
|
@ -59,7 +42,7 @@ class PushNotification {
|
|||
handleNotification = (data, foreground, userInteraction) => {
|
||||
this.deviceNotification = {
|
||||
data,
|
||||
foreground: foreground || (!userInteraction && AppState.currentState === 'active'),
|
||||
foreground,
|
||||
message: data.message,
|
||||
userInfo: data.userInfo,
|
||||
userInteraction,
|
||||
|
|
@ -90,19 +73,9 @@ class PushNotification {
|
|||
this.onNotification = options.onNotification;
|
||||
this.onReply = options.onReply;
|
||||
|
||||
NotificationsIOS.addEventListener('remoteNotificationsRegistered', (deviceToken) => {
|
||||
if (this.onRegister) {
|
||||
this.onRegister({token: deviceToken});
|
||||
}
|
||||
});
|
||||
this.requestPermissions([replyCategory]);
|
||||
|
||||
if (options.requestPermissions) {
|
||||
this.requestPermissions([replyCategory]);
|
||||
}
|
||||
|
||||
if (options.popInitialNotification) {
|
||||
NotificationsIOS.consumeBackgroundQueue();
|
||||
}
|
||||
NotificationsIOS.consumeBackgroundQueue();
|
||||
}
|
||||
|
||||
requestPermissions = (permissions) => {
|
||||
|
|
@ -136,6 +109,43 @@ class PushNotification {
|
|||
NotificationsIOS.cancelAllLocalNotifications();
|
||||
}
|
||||
|
||||
onNotificationReceivedBackground = (notification) => {
|
||||
const userInteraction = AppState.currentState === 'active';
|
||||
|
||||
// mark the app as started as soon as possible
|
||||
if (userInteraction) {
|
||||
ephemeralStore.appStartedFromPushNotification = true;
|
||||
}
|
||||
|
||||
const info = {
|
||||
...notification.getData(),
|
||||
message: notification.getMessage(),
|
||||
};
|
||||
this.handleNotification(info, false, userInteraction);
|
||||
};
|
||||
|
||||
onNotificationReceivedForeground = (notification) => {
|
||||
const info = {
|
||||
...notification.getData(),
|
||||
message: notification.getMessage(),
|
||||
};
|
||||
this.handleNotification(info, true, false);
|
||||
};
|
||||
|
||||
onNotificationOpened = (notification) => {
|
||||
const info = {
|
||||
...notification.getData(),
|
||||
message: notification.getMessage(),
|
||||
};
|
||||
this.handleNotification(info, false, true);
|
||||
};
|
||||
|
||||
onRemoteNotificationsRegistered = (deviceToken) => {
|
||||
if (this.onRegister) {
|
||||
this.onRegister({token: deviceToken});
|
||||
}
|
||||
};
|
||||
|
||||
setApplicationIconBadgeNumber(number) {
|
||||
const count = number < 0 ? 0 : number;
|
||||
NotificationsIOS.setBadgesCount(count);
|
||||
|
|
|
|||
|
|
@ -55,11 +55,6 @@ class PushNotificationUtils {
|
|||
let unsubscribeFromStore = null;
|
||||
let stopLoadingNotification = false;
|
||||
|
||||
// mark the app as started as soon as possible
|
||||
if (!ephemeralStore.appStarted) {
|
||||
ephemeralStore.appStartedFromPushNotification = true;
|
||||
}
|
||||
|
||||
const {data, foreground, message, userInfo, userInteraction} = deviceNotification;
|
||||
const notification = {
|
||||
data,
|
||||
|
|
|
|||
Loading…
Reference in a new issue