Page MenuHomePhabricator

D6815.id22825.diff
No OneTemporary

D6815.id22825.diff

diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js
--- a/keyserver/src/responders/website-responders.js
+++ b/keyserver/src/responders/website-responders.js
@@ -396,7 +396,7 @@
},
nextLocalID: 0,
cookie: undefined,
- deviceToken: undefined,
+ deviceToken: null,
dataLoaded: viewer.loggedIn,
windowActive: true,
userPolicies: {},
diff --git a/keyserver/src/updaters/device-token-updaters.js b/keyserver/src/updaters/device-token-updaters.js
--- a/keyserver/src/updaters/device-token-updaters.js
+++ b/keyserver/src/updaters/device-token-updaters.js
@@ -1,9 +1,6 @@
// @flow
-import {
- type DeviceTokenUpdateRequest,
- isDeviceType,
-} from 'lib/types/device-types.js';
+import { type DeviceTokenUpdateRequest } from 'lib/types/device-types.js';
import { ServerError } from 'lib/utils/errors.js';
import { dbQuery, SQL } from '../database/database.js';
@@ -14,7 +11,7 @@
update: DeviceTokenUpdateRequest,
): Promise<void> {
const deviceType = update.platformDetails?.platform ?? update.deviceType;
- if (!isDeviceType(deviceType)) {
+ if (deviceType === undefined) {
throw new ServerError('invalid_parameters');
}
diff --git a/lib/selectors/account-selectors.js b/lib/selectors/account-selectors.js
--- a/lib/selectors/account-selectors.js
+++ b/lib/selectors/account-selectors.js
@@ -4,12 +4,10 @@
import { currentCalendarQuery } from './nav-selectors.js';
import type { LogInExtraInfo } from '../types/account-types.js';
-import { isDeviceType } from '../types/device-types.js';
import type { CalendarQuery } from '../types/entry-types.js';
import type { AppState } from '../types/redux-types.js';
import type { PreRequestUserState } from '../types/session-types.js';
import type { CurrentUserInfo } from '../types/user-types.js';
-import { getConfig } from '../utils/config.js';
const logInExtraInfoSelector: (
state: AppState,
@@ -21,8 +19,7 @@
calendarQuery: (calendarActive: boolean) => CalendarQuery,
) => {
let deviceTokenUpdateRequest = null;
- const platform = getConfig().platformDetails.platform;
- if (deviceToken && isDeviceType(platform)) {
+ if (deviceToken) {
deviceTokenUpdateRequest = { deviceToken };
}
// Return a function since we depend on the time of evaluation
diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js
--- a/lib/types/redux-types.js
+++ b/lib/types/redux-types.js
@@ -118,7 +118,7 @@
};
export type WebAppState = BaseAppState<*> & {
sessionID: ?string,
- deviceToken?: void,
+ deviceToken: ?string,
cookie?: void,
primaryIdentityPublicKey: ?string,
pushApiPublicKey: ?string,
diff --git a/lib/utils/sanitization.js b/lib/utils/sanitization.js
--- a/lib/utils/sanitization.js
+++ b/lib/utils/sanitization.js
@@ -300,7 +300,7 @@
state = { ...oldState, cookie: null };
}
if (state.deviceToken !== undefined && state.deviceToken !== null) {
- const oldState: NativeAppState = state;
+ const oldState: AppState = state;
state = { ...oldState, deviceToken: null };
}
const stateCopy = clone(state);
diff --git a/web/redux/device-token.reducer.js b/web/redux/device-token.reducer.js
new file mode 100644
--- /dev/null
+++ b/web/redux/device-token.reducer.js
@@ -0,0 +1,38 @@
+// @flow
+
+import { setDeviceTokenActionTypes } from 'lib/actions/device-actions.js';
+import {
+ deleteAccountActionTypes,
+ logOutActionTypes,
+} from 'lib/actions/user-actions.js';
+import { incrementalStateSyncActionType } from 'lib/types/socket-types.js';
+import { updateTypes } from 'lib/types/update-types.js';
+import { setNewSessionActionType } from 'lib/utils/action-utils.js';
+
+import type { Action } from '../redux/redux-setup.js';
+
+export function reduceDeviceToken(state: ?string, action: Action): ?string {
+ if (action.type === setDeviceTokenActionTypes.success) {
+ return action.payload;
+ }
+ if (
+ action.type === logOutActionTypes.success ||
+ action.type === deleteAccountActionTypes.success ||
+ (action.type === setNewSessionActionType &&
+ action.payload.sessionChange.cookieInvalidated)
+ ) {
+ return null;
+ }
+ 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;
+}
diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js
--- a/web/redux/redux-setup.js
+++ b/web/redux/redux-setup.js
@@ -40,6 +40,7 @@
clearCalendarCommunityFilter,
} from './action-types.js';
import { reduceDeviceID } from './device-id-reducer.js';
+import { reduceDeviceToken } from './device-token.reducer.js';
import reduceNavInfo from './nav-reducer.js';
import {
reducePrimaryIdentityPublicKey,
@@ -69,7 +70,7 @@
urlPrefix: string,
windowDimensions: WindowDimensions,
cookie?: void,
- deviceToken?: void,
+ deviceToken: ?string,
baseHref: string,
connection: ConnectionInfo,
watchedThreadIDs: $ReadOnlyArray<string>,
@@ -198,6 +199,7 @@
state.threadStore.threadInfos,
),
deviceID: reduceDeviceID(state.deviceID, action),
+ deviceToken: reduceDeviceToken(state.deviceToken, action),
primaryIdentityPublicKey: reducePrimaryIdentityPublicKey(
state.primaryIdentityPublicKey,
action,

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 7:46 PM (18 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692272
Default Alt Text
D6815.id22825.diff (5 KB)

Event Timeline