2022-03-04 19:48:44 +00:00
|
|
|
// Copyright 2020-2022 Signal Messenger, LLC
|
2020-12-08 19:37:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-07-20 21:29:09 +00:00
|
|
|
import casual from 'casual';
|
2021-03-11 21:29:31 +00:00
|
|
|
import { sample } from 'lodash';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
2021-10-26 22:59:08 +00:00
|
|
|
import { UUID } from '../../types/UUID';
|
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { getRandomColor } from './getRandomColor';
|
2022-03-16 17:30:14 +00:00
|
|
|
import { ConversationColors } from '../../types/Colors';
|
2020-12-08 19:37:04 +00:00
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
export const getAvatarPath = (): string =>
|
|
|
|
sample([
|
|
|
|
'/fixtures/kitten-1-64-64.jpg',
|
|
|
|
'/fixtures/kitten-2-64-64.jpg',
|
|
|
|
'/fixtures/kitten-3-64-64.jpg',
|
|
|
|
]) || '';
|
|
|
|
|
2020-12-08 19:37:04 +00:00
|
|
|
export function getDefaultConversation(
|
2021-03-11 21:29:31 +00:00
|
|
|
overrideProps: Partial<ConversationType> = {}
|
2020-12-08 19:37:04 +00:00
|
|
|
): ConversationType {
|
2022-07-20 21:29:09 +00:00
|
|
|
const firstName = casual.first_name;
|
|
|
|
const lastName = casual.last_name;
|
2021-03-11 21:29:31 +00:00
|
|
|
|
2020-12-08 19:37:04 +00:00
|
|
|
return {
|
2021-05-07 22:21:10 +00:00
|
|
|
acceptedMessageRequest: true,
|
2022-03-04 21:14:52 +00:00
|
|
|
avatarPath: getAvatarPath(),
|
2021-11-02 23:01:13 +00:00
|
|
|
badges: [],
|
2022-07-20 21:29:09 +00:00
|
|
|
e164: `+${casual.phone.replace(/-/g, '')}`,
|
2022-03-16 17:30:14 +00:00
|
|
|
conversationColor: ConversationColors[0],
|
2021-08-06 00:17:05 +00:00
|
|
|
color: getRandomColor(),
|
2021-05-07 22:21:10 +00:00
|
|
|
firstName,
|
2022-07-20 21:29:09 +00:00
|
|
|
id: UUID.generate().toString(),
|
2021-05-07 22:21:10 +00:00
|
|
|
isMe: false,
|
2022-07-20 21:29:09 +00:00
|
|
|
lastUpdated: casual.unix_time,
|
2020-12-08 19:37:04 +00:00
|
|
|
markedUnread: Boolean(overrideProps.markedUnread),
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames: [],
|
2021-03-11 21:29:31 +00:00
|
|
|
title: `${firstName} ${lastName}`,
|
2020-12-08 19:37:04 +00:00
|
|
|
type: 'direct' as const,
|
2021-10-26 22:59:08 +00:00
|
|
|
uuid: UUID.generate().toString(),
|
2020-12-08 19:37:04 +00:00
|
|
|
...overrideProps,
|
|
|
|
};
|
|
|
|
}
|
2021-10-26 22:59:08 +00:00
|
|
|
|
2022-08-10 18:37:19 +00:00
|
|
|
export function getDefaultGroup(
|
|
|
|
overrideProps: Partial<ConversationType> = {}
|
|
|
|
): ConversationType {
|
|
|
|
const memberships = Array.from(Array(casual.integer(1, 20)), () => ({
|
|
|
|
uuid: UUID.generate().toString(),
|
|
|
|
isAdmin: Boolean(casual.coin_flip),
|
|
|
|
}));
|
|
|
|
|
|
|
|
return {
|
|
|
|
acceptedMessageRequest: true,
|
|
|
|
announcementsOnly: false,
|
|
|
|
avatarPath: getAvatarPath(),
|
|
|
|
badges: [],
|
|
|
|
color: getRandomColor(),
|
|
|
|
conversationColor: ConversationColors[0],
|
|
|
|
groupDescription: casual.sentence,
|
|
|
|
groupId: UUID.generate().toString(),
|
|
|
|
groupLink: casual.url,
|
|
|
|
groupVersion: 2,
|
|
|
|
id: UUID.generate().toString(),
|
|
|
|
isMe: false,
|
|
|
|
lastUpdated: casual.unix_time,
|
|
|
|
markedUnread: Boolean(overrideProps.markedUnread),
|
|
|
|
membersCount: memberships.length,
|
|
|
|
memberships,
|
|
|
|
sharedGroupNames: [],
|
|
|
|
title: casual.title,
|
|
|
|
type: 'group' as const,
|
|
|
|
uuid: UUID.generate().toString(),
|
|
|
|
...overrideProps,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-26 22:59:08 +00:00
|
|
|
export function getDefaultConversationWithUuid(
|
|
|
|
overrideProps: Partial<ConversationType> = {},
|
|
|
|
uuid: UUIDStringType = UUID.generate().toString()
|
|
|
|
): ConversationType & { uuid: UUIDStringType } {
|
|
|
|
return {
|
|
|
|
...getDefaultConversation(overrideProps),
|
|
|
|
uuid,
|
|
|
|
};
|
|
|
|
}
|