signal-desktop/ts/state/selectors/items.ts

71 lines
2 KiB
TypeScript
Raw Normal View History

// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import { isInteger } from 'lodash';
2021-06-01 20:45:43 +00:00
import { ITEM_NAME as UNIVERSAL_EXPIRE_TIMER_ITEM } from '../../util/universalExpireTimer';
import { StateType } from '../reducer';
import { ItemsStateType } from '../ducks/items';
2021-06-02 21:05:09 +00:00
import {
ConversationColorType,
CustomColorType,
DEFAULT_CONVERSATION_COLOR,
2021-06-02 21:05:09 +00:00
} from '../../types/Colors';
import { getPreferredReactionEmoji as getPreferredReactionEmojiFromStoredValue } from '../../reactions/getPreferredReactionEmoji';
export const getItems = (state: StateType): ItemsStateType => state.items;
export const getUserAgent = createSelector(
getItems,
(state: ItemsStateType): string => state.userAgent as string
);
export const getPinnedConversationIds = createSelector(
getItems,
(state: ItemsStateType): Array<string> =>
(state.pinnedConversationIds || []) as Array<string>
);
2021-06-01 20:45:43 +00:00
export const getUniversalExpireTimer = createSelector(
getItems,
(state: ItemsStateType): number => state[UNIVERSAL_EXPIRE_TIMER_ITEM] || 0
);
2021-06-02 21:05:09 +00:00
export const getDefaultConversationColor = createSelector(
getItems,
(
state: ItemsStateType
): {
color: ConversationColorType;
customColorData?: {
id: string;
value: CustomColorType;
};
} => state.defaultConversationColor ?? DEFAULT_CONVERSATION_COLOR
2021-06-02 21:05:09 +00:00
);
2021-08-18 20:08:14 +00:00
export const getCustomColors = createSelector(
getItems,
(state: ItemsStateType): Record<string, CustomColorType> | undefined =>
state.customColors?.colors
);
export const getEmojiSkinTone = createSelector(
getItems,
({ skinTone }: Readonly<ItemsStateType>): number =>
typeof skinTone === 'number' &&
isInteger(skinTone) &&
skinTone >= 0 &&
skinTone <= 5
? skinTone
: 0
);
export const getPreferredReactionEmoji = createSelector(
getItems,
(state: Readonly<ItemsStateType>): Array<string> =>
getPreferredReactionEmojiFromStoredValue(state.preferredReactionEmoji)
);