2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
import { sample } from 'lodash';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { AvatarColors } from '../types/Colors';
|
2023-06-02 17:54:36 +00:00
|
|
|
import type { ConversationAttributesType } from '../model-types';
|
|
|
|
import type { AvatarColorType, CustomColorType } from '../types/Colors';
|
2020-08-13 20:53:45 +00:00
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const NEW_COLOR_NAMES = new Set(AvatarColors);
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
export function migrateColor(color?: string): AvatarColorType {
|
|
|
|
if (color && NEW_COLOR_NAMES.has(color)) {
|
|
|
|
return color;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
2021-08-06 00:17:05 +00:00
|
|
|
|
|
|
|
return sample(AvatarColors) || AvatarColors[0];
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
2023-06-02 17:54:36 +00:00
|
|
|
|
|
|
|
export function getCustomColorData(conversation: ConversationAttributesType): {
|
|
|
|
customColor?: CustomColorType;
|
|
|
|
customColorId?: string;
|
|
|
|
} {
|
|
|
|
if (conversation.conversationColor !== 'custom') {
|
|
|
|
return {
|
|
|
|
customColor: undefined,
|
|
|
|
customColorId: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
customColor: conversation.customColor,
|
|
|
|
customColorId: conversation.customColorId,
|
|
|
|
};
|
|
|
|
}
|