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 @@ -299,6 +299,7 @@ const statePromises = { navInfo: navInfoPromise, + deviceID: null, currentUserInfo: ((currentUserInfoPromise: any): Promise), sessionID: sessionIDPromise, entryStore: entryStorePromise, diff --git a/web/redux/action-types.js b/web/redux/action-types.js --- a/web/redux/action-types.js +++ b/web/redux/action-types.js @@ -1,3 +1,4 @@ // @flow export const updateWindowActiveActionType = 'UPDATE_WINDOW_ACTIVE'; +export const setDeviceIDActionType = 'SET_DEVICE_ID'; diff --git a/web/redux/device-id-reducer.js b/web/redux/device-id-reducer.js new file mode 100644 --- /dev/null +++ b/web/redux/device-id-reducer.js @@ -0,0 +1,19 @@ +// @flow + +import type { Action } from '../redux/redux-setup'; +import { deviceIDCharLength } from '../utils//device-id'; +import { setDeviceIDActionType } from './action-types'; + +const deviceIDRegex = new RegExp( + `^(ks|mobile|web):[a-zA-Z0-9]{${deviceIDCharLength.toString()}}$`, +); + +export function reduceDeviceID(state: ?string, action: Action): ?string { + if (action.type === setDeviceIDActionType) { + if (action.payload?.match(deviceIDRegex)) { + return action.payload; + } + 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 @@ -27,13 +27,18 @@ import { activeThreadSelector } from '../selectors/nav-selectors'; import { type NavInfo, updateNavInfoActionType } from '../types/nav-types'; -import { updateWindowActiveActionType } from './action-types'; +import { + updateWindowActiveActionType, + setDeviceIDActionType, +} from './action-types'; +import { reduceDeviceID } from './device-id-reducer'; import reduceNavInfo from './nav-reducer'; import { getVisibility } from './visibility'; export type WindowDimensions = { width: number, height: number }; export type AppState = { navInfo: NavInfo, + deviceID: ?string, currentUserInfo: ?CurrentUserInfo, sessionID: ?string, entryStore: EntryStore, @@ -73,6 +78,10 @@ | { type: 'UPDATE_WINDOW_ACTIVE', payload: boolean, + } + | { + type: 'SET_DEVICE_ID', + payload: string, }; export function reducer(oldState: AppState | void, action: Action): AppState { @@ -120,7 +129,10 @@ return oldState; } - if (action.type !== updateNavInfoActionType) { + if ( + action.type !== updateNavInfoActionType && + action.type !== setDeviceIDActionType + ) { state = baseReducer(state, action).state; } @@ -131,6 +143,7 @@ action, state.threadStore.threadInfos, ), + deviceID: reduceDeviceID(state.deviceID, action), }; return validateState(oldState, state);