2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2020-03-20 18:01:55 +00:00
|
|
|
import { trigger } from '../../shims/events';
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { LocaleMessagesType } from '../../types/I18N';
|
2023-01-13 00:24:59 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { MenuOptionsType } from '../../types/menu';
|
2023-01-13 00:24:59 +00:00
|
|
|
import type { NoopActionType } from './noop';
|
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
|
|
|
import * as OS from '../../OS';
|
|
|
|
import { ThemeType } from '../../types/Util';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// State
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
|
|
|
export type UserStateType = Readonly<{
|
2019-05-16 22:32:11 +00:00
|
|
|
attachmentsPath: string;
|
2023-01-13 00:24:59 +00:00
|
|
|
i18n: LocalizerType;
|
|
|
|
interactionMode: 'mouse' | 'keyboard';
|
|
|
|
isMainWindowFullScreen: boolean;
|
|
|
|
isMainWindowMaximized: boolean;
|
|
|
|
localeMessages: LocaleMessagesType;
|
|
|
|
menuOptions: MenuOptionsType;
|
|
|
|
osName: 'linux' | 'macos' | 'windows' | undefined;
|
|
|
|
ourACI: UUIDStringType | undefined;
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId: string | undefined;
|
|
|
|
ourDeviceId: number | undefined;
|
|
|
|
ourNumber: string | undefined;
|
2023-01-13 00:24:59 +00:00
|
|
|
ourPNI: UUIDStringType | undefined;
|
2019-11-07 21:36:16 +00:00
|
|
|
platform: string;
|
2022-02-23 18:48:40 +00:00
|
|
|
regionCode: string | undefined;
|
2023-01-13 00:24:59 +00:00
|
|
|
stickersPath: string;
|
|
|
|
tempPath: string;
|
2021-02-12 01:50:11 +00:00
|
|
|
theme: ThemeType;
|
2022-01-26 23:05:26 +00:00
|
|
|
version: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type UserChangedActionType = ReadonlyDeep<{
|
2019-01-14 21:49:58 +00:00
|
|
|
type: 'USER_CHANGED';
|
|
|
|
payload: {
|
2020-03-05 21:14:58 +00:00
|
|
|
ourConversationId?: string;
|
2021-06-17 17:15:10 +00:00
|
|
|
ourDeviceId?: number;
|
2022-07-08 20:46:25 +00:00
|
|
|
ourACI?: UUIDStringType;
|
|
|
|
ourPNI?: UUIDStringType;
|
2019-11-21 19:16:06 +00:00
|
|
|
ourNumber?: string;
|
|
|
|
regionCode?: string;
|
|
|
|
interactionMode?: 'mouse' | 'keyboard';
|
2021-02-12 01:50:11 +00:00
|
|
|
theme?: ThemeType;
|
2022-06-08 22:00:32 +00:00
|
|
|
isMainWindowMaximized?: boolean;
|
|
|
|
isMainWindowFullScreen?: boolean;
|
|
|
|
menuOptions?: MenuOptionsType;
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type UserActionType = ReadonlyDeep<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';
|
2021-02-12 01:50:11 +00:00
|
|
|
ourConversationId?: string;
|
2021-06-17 17:15:10 +00:00
|
|
|
ourDeviceId?: number;
|
2021-02-12 01:50:11 +00:00
|
|
|
ourNumber?: string;
|
2022-07-08 20:46:25 +00:00
|
|
|
ourACI?: UUIDStringType;
|
|
|
|
ourPNI?: UUIDStringType;
|
2021-02-12 01:50:11 +00:00
|
|
|
regionCode?: string;
|
|
|
|
theme?: ThemeType;
|
2022-06-08 22:00:32 +00:00
|
|
|
isMainWindowMaximized?: boolean;
|
|
|
|
isMainWindowFullScreen?: boolean;
|
|
|
|
menuOptions?: MenuOptionsType;
|
2019-01-14 21:49:58 +00:00
|
|
|
}): 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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-03 21:19:54 +00:00
|
|
|
const intlNotSetup = () => {
|
|
|
|
throw new Error('i18n not yet set up');
|
|
|
|
};
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// Reducer
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
export function getEmptyState(): UserStateType {
|
2023-01-13 00:24:59 +00:00
|
|
|
let osName: 'windows' | 'macos' | 'linux' | undefined;
|
|
|
|
|
|
|
|
if (OS.isWindows()) {
|
|
|
|
osName = 'windows';
|
|
|
|
} else if (OS.isMacOS()) {
|
|
|
|
osName = 'macos';
|
|
|
|
} else if (OS.isLinux()) {
|
|
|
|
osName = 'linux';
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
return {
|
2019-05-16 22:32:11 +00:00
|
|
|
attachmentsPath: 'missing',
|
2023-01-13 00:24:59 +00:00
|
|
|
i18n: Object.assign(intlNotSetup, {
|
|
|
|
getLocale: intlNotSetup,
|
|
|
|
getIntl: intlNotSetup,
|
|
|
|
isLegacyFormat: intlNotSetup,
|
2023-04-20 17:03:43 +00:00
|
|
|
getLocaleDirection: intlNotSetup,
|
2023-01-13 00:24:59 +00:00
|
|
|
}),
|
2019-11-21 19:16:06 +00:00
|
|
|
interactionMode: 'mouse',
|
2022-06-08 22:00:32 +00:00
|
|
|
isMainWindowMaximized: false,
|
|
|
|
isMainWindowFullScreen: false,
|
2023-01-13 00:24:59 +00:00
|
|
|
localeMessages: {},
|
2022-06-08 22:00:32 +00:00
|
|
|
menuOptions: {
|
|
|
|
development: false,
|
|
|
|
devTools: false,
|
|
|
|
includeSetup: false,
|
|
|
|
isProduction: true,
|
|
|
|
platform: 'unknown',
|
|
|
|
},
|
2023-01-13 00:24:59 +00:00
|
|
|
osName,
|
|
|
|
ourACI: undefined,
|
|
|
|
ourConversationId: 'missing',
|
|
|
|
ourDeviceId: 0,
|
|
|
|
ourNumber: 'missing',
|
|
|
|
ourPNI: undefined,
|
|
|
|
platform: 'missing',
|
|
|
|
regionCode: 'missing',
|
|
|
|
stickersPath: 'missing',
|
|
|
|
tempPath: 'missing',
|
2021-02-12 01:50:11 +00:00
|
|
|
theme: ThemeType.light,
|
2022-01-26 23:05:26 +00:00
|
|
|
version: '0.0.0',
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
2020-12-14 19:47:21 +00:00
|
|
|
state: Readonly<UserStateType> = getEmptyState(),
|
|
|
|
action: Readonly<UserActionType>
|
2019-01-14 21:49:58 +00:00
|
|
|
): UserStateType {
|
|
|
|
if (!state) {
|
|
|
|
return getEmptyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'USER_CHANGED') {
|
|
|
|
const { payload } = action;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|