2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2025-03-05 10:56:23 -08:00
|
|
|
import { AvatarColors } from '../types/Colors';
|
2023-06-02 13:54:36 -04:00
|
|
|
import type { ConversationAttributesType } from '../model-types';
|
|
|
|
import type { AvatarColorType, CustomColorType } from '../types/Colors';
|
2025-03-05 10:56:23 -08:00
|
|
|
import { generateAvatarColor } from '../Crypto';
|
2020-08-13 13:53:45 -07:00
|
|
|
|
2021-08-05 20:17:05 -04:00
|
|
|
const NEW_COLOR_NAMES = new Set(AvatarColors);
|
2018-06-27 13:53:49 -07:00
|
|
|
|
2024-03-15 07:20:33 -07:00
|
|
|
export function migrateColor(
|
2025-03-05 10:56:23 -08:00
|
|
|
color: string | undefined,
|
|
|
|
options: Parameters<typeof generateAvatarColor>[0]
|
2024-03-15 07:20:33 -07:00
|
|
|
): AvatarColorType {
|
2021-08-05 20:17:05 -04:00
|
|
|
if (color && NEW_COLOR_NAMES.has(color)) {
|
|
|
|
return color;
|
2018-06-27 13:53:49 -07:00
|
|
|
}
|
2021-08-05 20:17:05 -04:00
|
|
|
|
2025-03-05 10:56:23 -08:00
|
|
|
return generateAvatarColor(options);
|
2018-06-27 13:53:49 -07:00
|
|
|
}
|
2023-06-02 13:54:36 -04: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,
|
|
|
|
};
|
|
|
|
}
|