MM-26749 Fix race condition when open from PN (#4556)
* MM-26749 Fix race condition when open from PN * setStartFromNotification earlier * Fix Android race condition when closing the app with the back button
This commit is contained in:
parent
044ff3e425
commit
f79baea68f
6 changed files with 40 additions and 20 deletions
|
|
@ -13,7 +13,6 @@ import {getMyTeams, getMyTeamMembers} from '@mm-redux/actions/teams';
|
|||
import {Client4} from '@mm-redux/client';
|
||||
import {General} from '@mm-redux/constants';
|
||||
import EventEmitter from '@mm-redux/utils/event_emitter';
|
||||
import EphemeralStore from '@store/ephemeral_store';
|
||||
import initialState from '@store/initial_state';
|
||||
import {getStateForReset} from '@store/utils';
|
||||
|
||||
|
|
@ -133,9 +132,8 @@ export function handleSelectTeamAndChannel(teamId, channelId) {
|
|||
dispatch(batchActions(actions, 'BATCH_SELECT_TEAM_AND_CHANNEL'));
|
||||
}
|
||||
|
||||
EphemeralStore.setStartFromNotification(false);
|
||||
|
||||
console.log('channel switch from push notification to', channel?.display_name, (Date.now() - dt), 'ms'); //eslint-disable-line
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('channel switch from push notification to', channel?.display_name || channel?.id, (Date.now() - dt), 'ms');
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ class PushNotificationUtils {
|
|||
this.replyNotificationData = null;
|
||||
}
|
||||
|
||||
configure = () => {
|
||||
PushNotifications.configure({
|
||||
configure = async () => {
|
||||
return PushNotifications.configure({
|
||||
onRegister: this.onRegisterDevice,
|
||||
onNotification: this.onPushNotification,
|
||||
onReply: this.onPushNotificationReply,
|
||||
|
|
@ -50,8 +50,6 @@ class PushNotificationUtils {
|
|||
};
|
||||
|
||||
loadFromNotification = async (notification) => {
|
||||
// Set appStartedFromPushNotification to avoid channel screen to call selectInitialChannel
|
||||
EphemeralStore.setStartFromNotification(true);
|
||||
await Store.redux.dispatch(loadFromPushNotification(notification));
|
||||
|
||||
// if we have a componentId means that the app is already initialized
|
||||
|
|
|
|||
|
|
@ -29,15 +29,15 @@ import {captureJSException} from '@utils/sentry';
|
|||
|
||||
const init = async () => {
|
||||
const credentials = await getAppCredentials();
|
||||
const MMKVStorage = await getStorage();
|
||||
|
||||
const {store} = configureStore(MMKVStorage);
|
||||
if (EphemeralStore.appStarted) {
|
||||
launchApp(credentials);
|
||||
return;
|
||||
}
|
||||
|
||||
pushNotifications.configure();
|
||||
const MMKVStorage = await getStorage();
|
||||
const {store} = configureStore(MMKVStorage);
|
||||
|
||||
await pushNotifications.configure();
|
||||
globalEventHandler.configure({
|
||||
launchApp,
|
||||
});
|
||||
|
|
@ -63,6 +63,8 @@ const launchApp = (credentials) => {
|
|||
if (valid) {
|
||||
store.dispatch(loadMe());
|
||||
await globalEventHandler.configureAnalytics();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Launch app in Channel screen');
|
||||
resetToChannel({skipMetrics: true});
|
||||
} else {
|
||||
const error = new Error(`Previous app version "${previousVersion}" is invalid.`);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ class PushNotification {
|
|||
|
||||
NotificationsAndroid.setNotificationOpenedListener((notification) => {
|
||||
if (notification) {
|
||||
EphemeralStore.setStartFromNotification(true);
|
||||
const data = notification.getData();
|
||||
this.handleNotification(data, true);
|
||||
}
|
||||
|
|
@ -38,15 +39,16 @@ class PushNotification {
|
|||
}
|
||||
|
||||
handleNotification = (data, userInteraction) => {
|
||||
const foreground = !userInteraction && AppState.currentState === 'active';
|
||||
this.deviceNotification = {
|
||||
data,
|
||||
foreground: !userInteraction && AppState.currentState === 'active',
|
||||
foreground,
|
||||
message: data.message,
|
||||
userInfo: data.userInfo,
|
||||
userInteraction,
|
||||
};
|
||||
|
||||
if (this.onNotification) {
|
||||
if (this.onNotification && (foreground || userInteraction)) {
|
||||
this.onNotification(this.deviceNotification);
|
||||
}
|
||||
};
|
||||
|
|
@ -59,21 +61,29 @@ class PushNotification {
|
|||
this.onRegister({token: this.deviceToken});
|
||||
}
|
||||
|
||||
if (options.popInitialNotification) {
|
||||
return new Promise((resolve) => {
|
||||
if (!options.popInitialNotification) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
PendingNotifications.getInitialNotification().
|
||||
then((notification) => {
|
||||
if (notification) {
|
||||
const data = notification.getData();
|
||||
if (data) {
|
||||
EphemeralStore.appStartedFromPushNotification = true;
|
||||
EphemeralStore.setStartFromNotification(true);
|
||||
this.handleNotification(data, true);
|
||||
}
|
||||
}
|
||||
}).
|
||||
catch((err) => {
|
||||
console.log('Android getInitialNotifiation() failed', err); //eslint-disable-line no-console
|
||||
}).
|
||||
finally(() => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
localNotificationSchedule(notification) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,12 @@ class PushNotification {
|
|||
|
||||
this.requestNotificationReplyPermissions();
|
||||
|
||||
if (options.popInitialNotification) {
|
||||
return new Promise((resolve) => {
|
||||
if (!options.popInitialNotification) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
NotificationsIOS.getInitialNotification().
|
||||
then((notification) => {
|
||||
if (notification) {
|
||||
|
|
@ -64,8 +69,11 @@ class PushNotification {
|
|||
}).
|
||||
catch((err) => {
|
||||
console.log('iOS getInitialNotifiation() failed', err); //eslint-disable-line no-console
|
||||
}).
|
||||
finally(() => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
requestNotificationReplyPermissions = () => {
|
||||
|
|
|
|||
|
|
@ -184,7 +184,11 @@ export default class ChannelBase extends PureComponent {
|
|||
|
||||
loadChannels = (teamId) => {
|
||||
const {loadChannelsForTeam, selectInitialChannel} = this.props.actions;
|
||||
if (!EphemeralStore.getStartFromNotification()) {
|
||||
if (EphemeralStore.getStartFromNotification()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Switch to channel from a push notification');
|
||||
EphemeralStore.setStartFromNotification(false);
|
||||
} else {
|
||||
loadChannelsForTeam(teamId).then((result) => {
|
||||
if (result?.error) {
|
||||
this.setState({channelsRequestFailed: true});
|
||||
|
|
|
|||
Loading…
Reference in a new issue