diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -11,7 +11,6 @@ } from '../redux/action-types'; import { store, dispatch } from '../redux/redux-setup'; import { getFirebase } from './firebase'; -import { saveMessageInfos } from './utils'; const androidNotificationChannelID = 'default'; const vibrationSpec = [500, 500]; @@ -27,11 +26,6 @@ const firebase = getFirebase(); const { data } = message; - const { messageInfos } = data; - if (messageInfos) { - saveMessageInfos(messageInfos, updatesCurrentAsOf); - } - const { rescind, rescindID } = data; if (rescind) { invariant(rescindID, 'rescind message without notifID'); diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js --- a/native/push/push-handler.react.js +++ b/native/push/push-handler.react.js @@ -12,12 +12,14 @@ setDeviceTokenActionTypes, setDeviceToken, } from 'lib/actions/device-actions'; +import { saveMessagesActionType } from 'lib/actions/message-actions'; import { unreadCount, threadInfoSelector, } from 'lib/selectors/thread-selectors'; import { isLoggedIn } from 'lib/selectors/user-selectors'; import { mergePrefixIntoBody } from 'lib/shared/notif-utils'; +import type { RawMessageInfo } from 'lib/types/message-types'; import type { Dispatch } from 'lib/types/redux-types'; import { type ConnectionInfo } from 'lib/types/socket-types'; import { type ThreadInfo } from 'lib/types/thread-types'; @@ -59,7 +61,6 @@ requestIOSPushPermissions, iosPushPermissionResponseReceived, } from './ios'; -import { saveMessageInfos } from './utils'; LogBox.ignoreLogs([ // react-native-firebase @@ -442,8 +443,18 @@ } } - saveMessageInfos(messageInfosString: string) { - saveMessageInfos(messageInfosString, this.props.updatesCurrentAsOf); + saveMessageInfos(messageInfosString: ?string) { + if (!messageInfosString) { + return; + } + const rawMessageInfos: $ReadOnlyArray = JSON.parse( + messageInfosString, + ); + const { updatesCurrentAsOf } = this.props; + this.props.dispatch({ + type: saveMessagesActionType, + payload: { rawMessageInfos, updatesCurrentAsOf }, + }); } iosForegroundNotificationReceived = notification => { @@ -471,9 +482,7 @@ return; } const messageInfos = notification.getData().messageInfos; - if (messageInfos) { - this.saveMessageInfos(messageInfos); - } + this.saveMessageInfos(messageInfos); let title = null; let body = notification.getMessage(); if (notification.getData().title) { @@ -501,9 +510,7 @@ return; } const messageInfos = notification.getData().messageInfos; - if (messageInfos) { - this.saveMessageInfos(messageInfos); - } + this.saveMessageInfos(messageInfos); this.onPressNotificationForThread(threadID, true); notification.finish(NotificationsIOS.FetchResult.NewData); }; @@ -538,6 +545,11 @@ androidMessageReceived = async (message: RemoteMessage) => { this.onPushNotifBootsApp(); + + const { data } = message; + const { messageInfos } = data; + this.saveMessageInfos(messageInfos); + handleAndroidMessage( message, this.props.updatesCurrentAsOf, diff --git a/native/push/utils.js b/native/push/utils.js deleted file mode 100644 --- a/native/push/utils.js +++ /dev/null @@ -1,21 +0,0 @@ -// @flow - -import { saveMessagesActionType } from 'lib/actions/message-actions'; -import type { RawMessageInfo } from 'lib/types/message-types'; - -import { dispatch } from '../redux/redux-setup'; - -function saveMessageInfos( - messageInfosString: string, - updatesCurrentAsOf: number, -) { - const messageInfos: $ReadOnlyArray = JSON.parse( - messageInfosString, - ); - dispatch({ - type: saveMessagesActionType, - payload: { rawMessageInfos: messageInfos, updatesCurrentAsOf }, - }); -} - -export { saveMessageInfos };