diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -6,11 +6,7 @@ import { mergePrefixIntoBody } from 'lib/shared/notif-utils'; -import { - recordAndroidNotificationActionType, - rescindAndroidNotificationActionType, -} from '../redux/action-types'; -import { store, dispatch } from '../redux/redux-setup'; +import { store } from '../redux/redux-setup'; import { getFirebase } from './firebase'; type CommAndroidNotificationsModuleType = { @@ -37,10 +33,6 @@ const { rescind, rescindID } = data; if (rescind) { invariant(rescindID, 'rescind message without notifID'); - dispatch({ - type: rescindAndroidNotificationActionType, - payload: { notifID: rescindID, threadID: data.threadID }, - }); return; } @@ -71,15 +63,6 @@ notification.setTitle(title); } firebase.notifications().displayNotification(notification); - - // We keep track of what notifs have been rendered for a given thread so - // that we can clear them immediately (without waiting for the rescind) - // when the user navigates to that thread. Since we can't do this while - // the app is closed, we rely on the rescind notif in that case. - dispatch({ - type: recordAndroidNotificationActionType, - payload: { threadID, notifID: id }, - }); } async function androidBackgroundMessageTask(message: RemoteMessage) { diff --git a/native/push/reducer.js b/native/push/reducer.js deleted file mode 100644 --- a/native/push/reducer.js +++ /dev/null @@ -1,91 +0,0 @@ -// @flow - -import { - logOutActionTypes, - deleteAccountActionTypes, -} from 'lib/actions/user-actions'; -import { setNewSessionActionType } from 'lib/utils/action-utils'; - -import { - recordAndroidNotificationActionType, - clearAndroidNotificationsActionType, - rescindAndroidNotificationActionType, - type Action, -} from '../redux/action-types'; - -type RecordAndroidNotificationPayload = { - +threadID: string, - +notifID: string, -}; - -type ClearAndroidNotificationsPayload = { - +threadID: string, -}; - -type RescindAndroidNotificationPayload = { - +notifID: string, - +threadID: string, -}; - -export type AndroidNotificationActions = - | { - +type: 'RECORD_ANDROID_NOTIFICATION', - +payload: RecordAndroidNotificationPayload, - } - | { - +type: 'CLEAR_ANDROID_NOTIFICATIONS', - +payload: ClearAndroidNotificationsPayload, - } - | { - +type: 'RESCIND_ANDROID_NOTIFICATION', - +payload: RescindAndroidNotificationPayload, - }; - -function reduceThreadIDsToNotifIDs( - state: { [threadID: string]: string[] }, - action: Action, -): { [threadID: string]: string[] } { - if (action.type === recordAndroidNotificationActionType) { - const existingNotifIDs = state[action.payload.threadID]; - let set; - if (existingNotifIDs) { - set = new Set([...existingNotifIDs, action.payload.notifID]); - } else { - set = new Set([action.payload.notifID]); - } - return { - ...state, - [action.payload.threadID]: [...set], - }; - } else if (action.type === clearAndroidNotificationsActionType) { - if (!state[action.payload.threadID]) { - return state; - } - return { - ...state, - [action.payload.threadID]: [], - }; - } else if (action.type === rescindAndroidNotificationActionType) { - const { threadID, notifID } = action.payload; - const existingNotifIDs = state[threadID]; - if (!existingNotifIDs) { - return state; - } - const filtered = existingNotifIDs.filter(id => id !== notifID); - if (filtered.length === existingNotifIDs.length) { - return state; - } - return { ...state, [threadID]: filtered }; - } else if ( - action.type === logOutActionTypes.success || - action.type === deleteAccountActionTypes.success || - (action.type === setNewSessionActionType && - action.payload.sessionChange.cookieInvalidated) - ) { - return {}; - } else { - return state; - } -} - -export { reduceThreadIDsToNotifIDs }; diff --git a/native/redux/action-types.js b/native/redux/action-types.js --- a/native/redux/action-types.js +++ b/native/redux/action-types.js @@ -6,7 +6,6 @@ import type { Shape } from 'lib/types/core'; import type { BaseAction } from 'lib/types/redux-types'; -import type { AndroidNotificationActions } from '../push/reducer'; import type { DeviceCameraInfo } from '../types/camera'; import type { ConnectivityInfo } from '../types/connectivity'; import type { GlobalThemeInfo } from '../types/themes'; @@ -16,12 +15,6 @@ export const resetUserStateActionType = 'RESET_USER_STATE'; export const recordNotifPermissionAlertActionType = 'RECORD_NOTIF_PERMISSION_ALERT'; -export const recordAndroidNotificationActionType = - 'RECORD_ANDROID_NOTIFICATION'; -export const clearAndroidNotificationsActionType = - 'CLEAR_ANDROID_NOTIFICATIONS'; -export const rescindAndroidNotificationActionType = - 'RESCIND_ANDROID_NOTIFICATION'; export const updateDimensionsActiveType = 'UPDATE_DIMENSIONS'; export const updateConnectivityActiveType = 'UPDATE_CONNECTIVITY'; export const updateThemeInfoActionType = 'UPDATE_THEME_INFO'; @@ -34,13 +27,10 @@ export const backgroundActionTypes: Set = new Set([ saveMessagesActionType, - recordAndroidNotificationActionType, - rescindAndroidNotificationActionType, ]); export type Action = | BaseAction - | AndroidNotificationActions | { +type: 'SET_REDUX_STATE', +payload: { +state: AppState, +hideFromMonitor: boolean }, diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -58,7 +58,6 @@ deviceToken: state.deviceToken, urlPrefix: state.urlPrefix, customServer: state.customServer, - threadIDsToNotifIDs: state.threadIDsToNotifIDs, notifPermissionAlertInfo: state.notifPermissionAlertInfo, messageSentFromRoute: state.messageSentFromRoute, _persist: state._persist, @@ -467,6 +466,10 @@ return state; }, + [34]: state => { + const { threadIDsToNotifIDs, ...stateSansThreadIDsToNotifIDs } = state; + return stateSansThreadIDsToNotifIDs; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -547,7 +550,7 @@ 'storeLoaded', ], debug: __DEV__, - version: 33, + version: 34, transforms: [messageStoreMessagesBlocklistTransform], migrate: (createMigrate(migrations, { debug: __DEV__ }): any), timeout: ((__DEV__ ? 0 : undefined): number | void), diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -43,7 +43,6 @@ import { getGlobalNavContext } from '../navigation/icky-global'; import { activeMessageListSelector } from '../navigation/nav-selectors'; import { defaultNotifPermissionAlertInfo } from '../push/alerts'; -import { reduceThreadIDsToNotifIDs } from '../push/reducer'; import reactotron from '../reactotron'; import { defaultDeviceCameraInfo } from '../types/camera'; import { defaultConnectivityInfo } from '../types/connectivity'; @@ -59,9 +58,6 @@ import { resetUserStateActionType, recordNotifPermissionAlertActionType, - recordAndroidNotificationActionType, - clearAndroidNotificationsActionType, - rescindAndroidNotificationActionType, updateDimensionsActiveType, updateConnectivityActiveType, updateThemeInfoActionType, @@ -109,7 +105,6 @@ dataLoaded: false, urlPrefix: defaultURLPrefix, customServer: natNodeServer, - threadIDsToNotifIDs: {}, notifPermissionAlertInfo: defaultNotifPermissionAlertInfo, connection: defaultConnectionInfo(Platform.OS), watchedThreadIDs: [], @@ -227,19 +222,6 @@ return state; } - const threadIDsToNotifIDs = reduceThreadIDsToNotifIDs( - state.threadIDsToNotifIDs, - action, - ); - state = { ...state, threadIDsToNotifIDs }; - if ( - action.type === recordAndroidNotificationActionType || - action.type === clearAndroidNotificationsActionType || - action.type === rescindAndroidNotificationActionType - ) { - return state; - } - if (action.type === setCustomServer) { return { ...state, diff --git a/native/redux/state-types.js b/native/redux/state-types.js --- a/native/redux/state-types.js +++ b/native/redux/state-types.js @@ -40,7 +40,6 @@ dataLoaded: boolean, urlPrefix: string, customServer: ?string, - threadIDsToNotifIDs: { [threadID: string]: string[] }, notifPermissionAlertInfo: NotifPermissionAlertInfo, connection: ConnectionInfo, watchedThreadIDs: $ReadOnlyArray,