diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -5,11 +5,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'; const androidNotificationChannelID = 'default'; @@ -29,10 +25,6 @@ const { rescind, rescindID } = data; if (rescind) { invariant(rescindID, 'rescind message without notifID'); - dispatch({ - type: rescindAndroidNotificationActionType, - payload: { notifID: rescindID, threadID: data.threadID }, - }); return; } @@ -63,15 +55,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/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 @@ -2,7 +2,13 @@ import * as Haptics from 'expo-haptics'; import * as React from 'react'; -import { AppRegistry, Platform, Alert, LogBox } from 'react-native'; +import { + AppRegistry, + Platform, + Alert, + LogBox, + NativeModules, +} from 'react-native'; import type { RemoteMessage, NotificationOpen } from 'react-native-firebase'; import { Notification as InAppNotification } from 'react-native-in-app-message'; import NotificationsIOS from 'react-native-notifications'; @@ -41,10 +47,7 @@ import { activeMessageListSelector } from '../navigation/nav-selectors'; import { NavContext } from '../navigation/navigation-context'; import type { RootNavigationProp } from '../navigation/root-navigator.react'; -import { - recordNotifPermissionAlertActionType, - clearAndroidNotificationsActionType, -} from '../redux/action-types'; +import { recordNotifPermissionAlertActionType } from '../redux/action-types'; import { useSelector } from '../redux/redux-utils'; import { RootContext, type RootContextType } from '../root-context'; import type { EventSubscription } from '../types/react-native'; @@ -294,10 +297,9 @@ ), ); } else if (Platform.OS === 'android') { - this.props.dispatch({ - type: clearAndroidNotificationsActionType, - payload: { threadID: activeThread }, - }); + NativeModules.CommAndroidNotifications.removeAllActiveNotificationsForThread( + activeThread, + ); } } diff --git a/native/push/reducer.js b/native/push/reducer.js deleted file mode 100644 --- a/native/push/reducer.js +++ /dev/null @@ -1,93 +0,0 @@ -// @flow - -import { NativeModules } from 'react-native'; - -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) { - NativeModules.CommAndroidNotifications.removeAllActiveNotificationsForThread( - action.payload.threadID, - ); - 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, 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,