Page MenuHomePhabricator

D6885.diff
No OneTemporary

D6885.diff

diff --git a/lib/reducers/device-token-reducer.js b/lib/reducers/device-token-reducer.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/device-token-reducer.js
@@ -0,0 +1,25 @@
+// @flow
+
+import { setDeviceTokenActionTypes } from '../actions/device-actions.js';
+import type { BaseAction } from '../types/redux-types';
+import { incrementalStateSyncActionType } from '../types/socket-types.js';
+import { updateTypes } from '../types/update-types.js';
+
+function reduceDeviceToken(state: ?string, action: BaseAction): ?string {
+ if (action.type === setDeviceTokenActionTypes.success) {
+ return action.payload;
+ }
+ if (action.type === incrementalStateSyncActionType) {
+ for (const update of action.payload.updatesResult.newUpdates) {
+ if (
+ update.type === updateTypes.BAD_DEVICE_TOKEN &&
+ update.deviceToken === state
+ ) {
+ return null;
+ }
+ }
+ }
+ return state;
+}
+
+export { reduceDeviceToken };
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
@@ -7,13 +7,13 @@
import thunk from 'redux-thunk';
import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js';
-import { setDeviceTokenActionTypes } from 'lib/actions/device-actions.js';
import { siweAuthActionTypes } from 'lib/actions/siwe-actions.js';
import {
logOutActionTypes,
deleteAccountActionTypes,
logInActionTypes,
} from 'lib/actions/user-actions.js';
+import { reduceDeviceToken } from 'lib/reducers/device-token-reducer.js';
import baseReducer from 'lib/reducers/master-reducer.js';
import { processThreadStoreOperations } from 'lib/reducers/thread-reducer.js';
import {
@@ -26,12 +26,8 @@
import type { Dispatch, BaseAction } from 'lib/types/redux-types.js';
import { rehydrateActionType } from 'lib/types/redux-types.js';
import type { SetSessionPayload } from 'lib/types/session-types.js';
-import {
- defaultConnectionInfo,
- incrementalStateSyncActionType,
-} from 'lib/types/socket-types.js';
+import { defaultConnectionInfo } from 'lib/types/socket-types.js';
import type { ThreadStoreOperation } from 'lib/types/thread-types.js';
-import { updateTypes } from 'lib/types/update-types.js';
import { reduxLoggerMiddleware } from 'lib/utils/action-logger.js';
import { setNewSessionActionType } from 'lib/utils/action-utils.js';
import { convertMessageStoreOperationsToClientDBOperations } from 'lib/utils/message-ops-utils.js';
@@ -282,11 +278,6 @@
...state,
deviceOrientation: action.payload,
};
- } else if (action.type === setDeviceTokenActionTypes.success) {
- return {
- ...state,
- deviceToken: action.payload,
- };
} else if (action.type === updateThreadLastNavigatedActionType) {
const { threadID, time } = action.payload;
if (state.messageStore.threads[threadID]) {
@@ -313,23 +304,6 @@
...state,
cookie: action.payload.sessionChange.cookie,
};
- } else if (action.type === incrementalStateSyncActionType) {
- let wipeDeviceToken = false;
- for (const update of action.payload.updatesResult.newUpdates) {
- if (
- update.type === updateTypes.BAD_DEVICE_TOKEN &&
- update.deviceToken === state.deviceToken
- ) {
- wipeDeviceToken = true;
- break;
- }
- }
- if (wipeDeviceToken) {
- state = {
- ...state,
- deviceToken: null,
- };
- }
}
if (action.type === setStoreLoadedActionType) {
return {
@@ -358,6 +332,10 @@
}
}
+ state = {
+ ...state,
+ deviceToken: reduceDeviceToken(state.deviceToken, action),
+ };
const baseReducerResult = baseReducer(state, (action: BaseAction));
state = baseReducerResult.state;

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 9:22 AM (13 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690709
Default Alt Text
D6885.diff (3 KB)

Event Timeline