53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
// Copyright 2020-2022 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import casual from 'casual';
|
|
import { sample } from 'lodash';
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
|
import { UUID } from '../../types/UUID';
|
|
import type { UUIDStringType } from '../../types/UUID';
|
|
import { getRandomColor } from './getRandomColor';
|
|
import { ConversationColors } from '../../types/Colors';
|
|
|
|
export const getAvatarPath = (): string =>
|
|
sample([
|
|
'/fixtures/kitten-1-64-64.jpg',
|
|
'/fixtures/kitten-2-64-64.jpg',
|
|
'/fixtures/kitten-3-64-64.jpg',
|
|
]) || '';
|
|
|
|
export function getDefaultConversation(
|
|
overrideProps: Partial<ConversationType> = {}
|
|
): ConversationType {
|
|
const firstName = casual.first_name;
|
|
const lastName = casual.last_name;
|
|
|
|
return {
|
|
acceptedMessageRequest: true,
|
|
avatarPath: getAvatarPath(),
|
|
badges: [],
|
|
e164: `+${casual.phone.replace(/-/g, '')}`,
|
|
conversationColor: ConversationColors[0],
|
|
color: getRandomColor(),
|
|
firstName,
|
|
id: UUID.generate().toString(),
|
|
isMe: false,
|
|
lastUpdated: casual.unix_time,
|
|
markedUnread: Boolean(overrideProps.markedUnread),
|
|
sharedGroupNames: [],
|
|
title: `${firstName} ${lastName}`,
|
|
type: 'direct' as const,
|
|
uuid: UUID.generate().toString(),
|
|
...overrideProps,
|
|
};
|
|
}
|
|
|
|
export function getDefaultConversationWithUuid(
|
|
overrideProps: Partial<ConversationType> = {},
|
|
uuid: UUIDStringType = UUID.generate().toString()
|
|
): ConversationType & { uuid: UUIDStringType } {
|
|
return {
|
|
...getDefaultConversation(overrideProps),
|
|
uuid,
|
|
};
|
|
}
|