Files
Desktop/ts/util/migrateColor.ts
Scott Nonnenberg 99682a4981 Support for Notification Profiles
Co-authored-by: trevor-signal <trevor@signal.org>
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
2025-10-08 10:06:24 +10:00

38 lines
1.0 KiB
TypeScript

// Copyright 2018 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { AvatarColors } from '../types/Colors.js';
import type { ConversationAttributesType } from '../model-types.js';
import type { AvatarColorType, CustomColorType } from '../types/Colors.js';
import { generateAvatarColor } from '../Crypto.js';
const NEW_COLOR_NAMES = new Set(AvatarColors);
export function migrateColor(
color: string | undefined,
options: Parameters<typeof generateAvatarColor>[0]
): AvatarColorType {
if (color && NEW_COLOR_NAMES.has(color as AvatarColorType)) {
return color as AvatarColorType;
}
return generateAvatarColor(options);
}
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,
};
}