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
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2024-06-13 13:59:22 +00:00
|
|
|
import { type LocalizerType, ThemeType } from '../../types/Util';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { AciString, PniString } from '../../types/ServiceId';
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { LocaleMessagesType } from '../../types/I18N';
|
|
|
|
import type { MenuOptionsType } from '../../types/menu';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2024-06-13 13:59:22 +00:00
|
|
|
import type { CallingStateType } from '../ducks/calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { UserStateType } from '../ducks/user';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2022-01-26 23:05:26 +00:00
|
|
|
import { isAlpha, isBeta } from '../../util/version';
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export const getUser = (state: StateType): UserStateType => state.user;
|
|
|
|
|
|
|
|
export const getUserNumber = createSelector(
|
|
|
|
getUser,
|
2022-02-23 18:48:40 +00:00
|
|
|
(state: UserStateType): string | undefined => state.ourNumber
|
2019-01-14 21:49:58 +00:00
|
|
|
);
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export const getUserDeviceId = createSelector(
|
|
|
|
getUser,
|
2022-02-23 18:48:40 +00:00
|
|
|
(state: UserStateType): number | undefined => state.ourDeviceId
|
2021-06-17 17:15:10 +00:00
|
|
|
);
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export const getRegionCode = createSelector(
|
|
|
|
getUser,
|
2022-02-23 18:48:40 +00:00
|
|
|
(state: UserStateType): string | undefined => state.regionCode
|
2019-01-14 21:49:58 +00:00
|
|
|
);
|
|
|
|
|
2020-03-05 21:14:58 +00:00
|
|
|
export const getUserConversationId = createSelector(
|
|
|
|
getUser,
|
2022-02-23 18:48:40 +00:00
|
|
|
(state: UserStateType): string | undefined => state.ourConversationId
|
2020-03-05 21:14:58 +00:00
|
|
|
);
|
|
|
|
|
2022-07-08 20:46:25 +00:00
|
|
|
export const getUserACI = createSelector(
|
2020-03-05 21:14:58 +00:00
|
|
|
getUser,
|
2023-08-10 16:43:33 +00:00
|
|
|
(state: UserStateType): AciString | undefined => state.ourAci
|
2022-07-08 20:46:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getUserPNI = createSelector(
|
|
|
|
getUser,
|
2023-08-10 16:43:33 +00:00
|
|
|
(state: UserStateType): PniString | undefined => state.ourPni
|
2020-03-05 21:14:58 +00:00
|
|
|
);
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export const getIntl = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): LocalizerType => state.i18n
|
|
|
|
);
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
export const getLocaleMessages = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): LocaleMessagesType => state.localeMessages
|
|
|
|
);
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
export const getInteractionMode = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType) => state.interactionMode
|
|
|
|
);
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
export const getAttachmentsPath = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): string => state.attachmentsPath
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getStickersPath = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): string => state.stickersPath
|
|
|
|
);
|
2019-05-24 01:27:42 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
export const getPlatform = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): string => state.platform
|
|
|
|
);
|
|
|
|
|
2019-05-24 01:27:42 +00:00
|
|
|
export const getTempPath = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): string => state.tempPath
|
|
|
|
);
|
2021-02-12 01:50:11 +00:00
|
|
|
|
2024-06-13 13:59:22 +00:00
|
|
|
export const getPreferredTheme = createSelector(
|
2021-02-12 01:50:11 +00:00
|
|
|
getUser,
|
|
|
|
(state: UserStateType): ThemeType => state.theme
|
|
|
|
);
|
2022-01-26 23:05:26 +00:00
|
|
|
|
2024-06-13 13:59:22 +00:00
|
|
|
// Also defined in calling selectors, redefined to avoid circular dependency
|
|
|
|
const getIsInFullScreenCall = createSelector(
|
|
|
|
(state: StateType): CallingStateType => state.calling,
|
|
|
|
(state: CallingStateType): boolean =>
|
2024-09-18 23:29:14 +00:00
|
|
|
Boolean(
|
|
|
|
state.activeCallState?.state === 'Active' && !state.activeCallState.pip
|
|
|
|
)
|
2024-06-13 13:59:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getTheme = createSelector(
|
|
|
|
getPreferredTheme,
|
|
|
|
getIsInFullScreenCall,
|
|
|
|
(theme: ThemeType, isInCall: boolean): ThemeType => {
|
|
|
|
return isInCall ? ThemeType.dark : theme;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-01-26 23:05:26 +00:00
|
|
|
const getVersion = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType) => state.version
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getIsAlpha = createSelector(getVersion, isAlpha);
|
|
|
|
|
|
|
|
export const getIsBeta = createSelector(getVersion, isBeta);
|
2022-06-08 22:00:32 +00:00
|
|
|
|
|
|
|
export const getIsMainWindowMaximized = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): boolean => state.isMainWindowMaximized
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getIsMainWindowFullScreen = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): boolean => state.isMainWindowFullScreen
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getMenuOptions = createSelector(
|
|
|
|
getUser,
|
|
|
|
(state: UserStateType): MenuOptionsType => state.menuOptions
|
|
|
|
);
|
2023-01-18 23:31:10 +00:00
|
|
|
|
|
|
|
export const getIsMacOS = createSelector(
|
|
|
|
getPlatform,
|
|
|
|
(platform: string): boolean => platform === 'darwin'
|
|
|
|
);
|