Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3373482
D9816.id33203.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D9816.id33203.diff
View Options
diff --git a/lib/reducers/device-token-reducer.js b/lib/reducers/device-token-reducer.js
deleted file mode 100644
--- a/lib/reducers/device-token-reducer.js
+++ /dev/null
@@ -1,26 +0,0 @@
-// @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-enum.js';
-import { ashoatKeyserverID } from '../utils/validation-utils.js';
-
-function reduceDeviceToken(state: ?string, action: BaseAction): ?string {
- if (action.type === setDeviceTokenActionTypes.success) {
- return action.payload.deviceTokens[ashoatKeyserverID];
- }
- 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/lib/reducers/keyserver-reducer.js b/lib/reducers/keyserver-reducer.js
--- a/lib/reducers/keyserver-reducer.js
+++ b/lib/reducers/keyserver-reducer.js
@@ -1,9 +1,11 @@
// @flow
-import { reduceDeviceToken } from './device-token-reducer.js';
import { unsupervisedBackgroundActionType } from './lifecycle-state-reducer.js';
import { updateActivityActionTypes } from '../actions/activity-actions.js';
-import { updateLastCommunicatedPlatformDetailsActionType } from '../actions/device-actions.js';
+import {
+ updateLastCommunicatedPlatformDetailsActionType,
+ setDeviceTokenActionTypes,
+} from '../actions/device-actions.js';
import { addKeyserverActionType } from '../actions/keyserver-actions.js';
import { siweAuthActionTypes } from '../actions/siwe-actions.js';
import {
@@ -13,7 +15,7 @@
resetUserStateActionType,
} from '../actions/user-actions.js';
import { queueActivityUpdatesActionType } from '../types/activity-types.js';
-import type { KeyserverStore } from '../types/keyserver-types';
+import type { KeyserverInfos, KeyserverStore } from '../types/keyserver-types';
import type { BaseAction } from '../types/redux-types.js';
import {
fullStateSyncActionType,
@@ -22,6 +24,7 @@
setLateResponseActionType,
updateDisconnectedBarActionType,
} from '../types/socket-types.js';
+import { updateTypes } from '../types/update-types-enum.js';
import { processUpdatesActionType } from '../types/update-types.js';
import { setNewSessionActionType } from '../utils/action-utils.js';
import { getConfig } from '../utils/config.js';
@@ -119,6 +122,16 @@
};
} else if (action.type === incrementalStateSyncActionType) {
const { keyserverID } = action.payload;
+ let deviceToken = state.keyserverInfos[keyserverID].deviceToken;
+ for (const update of action.payload.updatesResult.newUpdates) {
+ if (
+ update.type === updateTypes.BAD_DEVICE_TOKEN &&
+ update.deviceToken === state.keyserverInfos[keyserverID].deviceToken
+ ) {
+ deviceToken = null;
+ break;
+ }
+ }
state = {
...state,
keyserverInfos: {
@@ -126,6 +139,7 @@
[keyserverID]: {
...state.keyserverInfos[keyserverID],
updatesCurrentAsOf: action.payload.updatesResult.currentAsOf,
+ deviceToken,
},
},
};
@@ -311,22 +325,18 @@
},
},
};
- }
-
- const deviceToken = reduceDeviceToken(
- state.keyserverInfos[ashoatKeyserverID].deviceToken,
- action,
- );
- if (deviceToken !== state.keyserverInfos[ashoatKeyserverID].deviceToken) {
+ } else if (action.type === setDeviceTokenActionTypes.success) {
+ const { deviceTokens } = action.payload;
+ const keyserverInfos: { ...KeyserverInfos } = { ...state.keyserverInfos };
+ for (const keyserverID in deviceTokens) {
+ keyserverInfos[keyserverID] = {
+ ...keyserverInfos[keyserverID],
+ deviceToken: deviceTokens[keyserverID],
+ };
+ }
state = {
...state,
- keyserverInfos: {
- ...state.keyserverInfos,
- [ashoatKeyserverID]: {
- ...state.keyserverInfos[ashoatKeyserverID],
- deviceToken,
- },
- },
+ keyserverInfos,
};
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 9:57 AM (21 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2587458
Default Alt Text
D9816.id33203.diff (4 KB)
Attached To
Mode
D9816: [lib] Inline reduceDeviceToken
Attached
Detach File
Event Timeline
Log In to Comment