Signal-Desktop/ts/util/migrateColor.ts

17 lines
458 B
TypeScript
Raw Normal View History

2021-01-07 18:06:09 +00:00
// Copyright 2018-2021 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';
import type { AvatarColorType } from '../types/Colors';
import { AvatarColors } from '../types/Colors';
2021-08-06 00:17:05 +00:00
const NEW_COLOR_NAMES = new Set(AvatarColors);
2021-08-06 00:17:05 +00:00
export function migrateColor(color?: string): AvatarColorType {
if (color && NEW_COLOR_NAMES.has(color)) {
return color;
}
2021-08-06 00:17:05 +00:00
return sample(AvatarColors) || AvatarColors[0];
}