Import/export avatar colors

This commit is contained in:
Fedor Indutny
2025-03-05 10:56:23 -08:00
committed by GitHub
parent 16d36053ea
commit aff9a3213e
16 changed files with 340 additions and 28 deletions

View File

@@ -1,29 +1,22 @@
// Copyright 2018 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { sample } from 'lodash';
import { AVATAR_COLOR_COUNT, AvatarColors } from '../types/Colors';
import { AvatarColors } from '../types/Colors';
import type { ConversationAttributesType } from '../model-types';
import type { AvatarColorType, CustomColorType } from '../types/Colors';
import type { ServiceIdString } from '../types/ServiceId';
import { generateAvatarColor } from '../Crypto';
const NEW_COLOR_NAMES = new Set(AvatarColors);
export function migrateColor(
serviceId?: ServiceIdString,
color?: string
color: string | undefined,
options: Parameters<typeof generateAvatarColor>[0]
): AvatarColorType {
if (color && NEW_COLOR_NAMES.has(color)) {
return color;
}
if (!serviceId) {
return sample(AvatarColors) || AvatarColors[0];
}
const index = (parseInt(serviceId.slice(-4), 16) || 0) % AVATAR_COLOR_COUNT;
return AvatarColors[index];
return generateAvatarColor(options);
}
export function getCustomColorData(conversation: ConversationAttributesType): {