2020-03-20 18:01:55 +00:00
|
|
|
import { trigger } from '../../shims/events';
|
|
|
|
|
|
|
|
import { NoopActionType } from './noop';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { LocalizerType } from '../../types/Util';
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
export type UserStateType = {
|
2019-05-16 22:32:11 +00:00
|
|
|
attachmentsPath: string;
|
|
|
|
stickersPath: string;
|
2019-05-24 01:27:42 +00:00
|
|
|
tempPath: string;
|
2020-03-05 21:14:58 +00:00
|
|
|
ourConversationId: string;
|
|
|
|
ourUuid: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
ourNumber: string;
|
2019-11-07 21:36:16 +00:00
|
|
|
platform: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
regionCode: string;
|
|
|
|
i18n: LocalizerType;
|
2019-11-21 19:16:06 +00:00
|
|
|
interactionMode: 'mouse' | 'keyboard';
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
type UserChangedActionType = {
|
|
|
|
type: 'USER_CHANGED';
|
|
|
|
payload: {
|
2020-03-05 21:14:58 +00:00
|
|
|
ourConversationId?: string;
|
|
|
|
ourUuid?: string;
|
2019-11-21 19:16:06 +00:00
|
|
|
ourNumber?: string;
|
|
|
|
regionCode?: string;
|
|
|
|
interactionMode?: 'mouse' | 'keyboard';
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
export type UserActionType = UserChangedActionType;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
userChanged,
|
2020-03-20 18:01:55 +00:00
|
|
|
manualReconnect,
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function userChanged(attributes: {
|
2019-12-03 20:02:50 +00:00
|
|
|
interactionMode?: 'mouse' | 'keyboard';
|
2020-03-05 21:14:58 +00:00
|
|
|
ourConversationId: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
ourNumber: string;
|
2020-03-05 21:14:58 +00:00
|
|
|
ourUuid: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
regionCode: string;
|
|
|
|
}): UserChangedActionType {
|
|
|
|
return {
|
|
|
|
type: 'USER_CHANGED',
|
|
|
|
payload: attributes,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:01:55 +00:00
|
|
|
function manualReconnect(): NoopActionType {
|
|
|
|
trigger('manualConnect');
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// Reducer
|
|
|
|
|
|
|
|
function getEmptyState(): UserStateType {
|
|
|
|
return {
|
2019-05-16 22:32:11 +00:00
|
|
|
attachmentsPath: 'missing',
|
|
|
|
stickersPath: 'missing',
|
2019-05-24 01:27:42 +00:00
|
|
|
tempPath: 'missing',
|
2020-03-05 21:14:58 +00:00
|
|
|
ourConversationId: 'missing',
|
|
|
|
ourUuid: 'missing',
|
2019-01-14 21:49:58 +00:00
|
|
|
ourNumber: 'missing',
|
|
|
|
regionCode: 'missing',
|
2019-11-07 21:36:16 +00:00
|
|
|
platform: 'missing',
|
2019-11-21 19:16:06 +00:00
|
|
|
interactionMode: 'mouse',
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: () => 'missing',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
2019-05-16 22:32:11 +00:00
|
|
|
state: UserStateType = getEmptyState(),
|
2019-01-14 21:49:58 +00:00
|
|
|
action: UserActionType
|
|
|
|
): UserStateType {
|
|
|
|
if (!state) {
|
|
|
|
return getEmptyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'USER_CHANGED') {
|
|
|
|
const { payload } = action;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|