2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 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';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { ServiceIdString } from '../../types/ServiceId';
|
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2023-01-25 23:51:08 +00:00
|
|
|
import type { GroupListItemConversationType } from '../../components/conversationList/GroupListItem';
|
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';
|
2022-11-19 08:31:18 +00:00
|
|
|
import { StorySendMode } from '../../types/Stories';
|
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,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
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}`,
|
2022-09-26 20:18:11 +00:00
|
|
|
titleNoDefault: `${firstName} ${lastName}`,
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId: generateAci(),
|
2020-12-08 19:37:04 +00:00
|
|
|
...overrideProps,
|
2022-11-19 08:31:18 +00:00
|
|
|
type: 'direct' as const,
|
|
|
|
acknowledgedGroupNameCollisions: undefined,
|
|
|
|
storySendMode: undefined,
|
2020-12-08 19:37:04 +00:00
|
|
|
};
|
|
|
|
}
|
2021-10-26 22:59:08 +00:00
|
|
|
|
2023-01-25 23:51:08 +00:00
|
|
|
export function getDefaultGroupListItem(
|
|
|
|
overrideProps: Partial<GroupListItemConversationType> = {}
|
|
|
|
): GroupListItemConversationType {
|
|
|
|
return {
|
|
|
|
...getDefaultGroup(),
|
|
|
|
disabledReason: undefined,
|
|
|
|
membersCount: 24,
|
|
|
|
memberships: [],
|
|
|
|
...overrideProps,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-10 18:37:19 +00:00
|
|
|
export function getDefaultGroup(
|
|
|
|
overrideProps: Partial<ConversationType> = {}
|
|
|
|
): ConversationType {
|
|
|
|
const memberships = Array.from(Array(casual.integer(1, 20)), () => ({
|
2023-08-16 20:54:39 +00:00
|
|
|
aci: generateAci(),
|
2022-08-10 18:37:19 +00:00
|
|
|
isAdmin: Boolean(casual.coin_flip),
|
|
|
|
}));
|
|
|
|
|
|
|
|
return {
|
|
|
|
acceptedMessageRequest: true,
|
|
|
|
announcementsOnly: false,
|
|
|
|
avatarPath: getAvatarPath(),
|
|
|
|
badges: [],
|
|
|
|
color: getRandomColor(),
|
|
|
|
conversationColor: ConversationColors[0],
|
|
|
|
groupDescription: casual.sentence,
|
2023-08-10 16:43:33 +00:00
|
|
|
groupId: generateUuid(),
|
2022-08-10 18:37:19 +00:00
|
|
|
groupLink: casual.url,
|
|
|
|
groupVersion: 2,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-08-10 18:37:19 +00:00
|
|
|
isMe: false,
|
|
|
|
lastUpdated: casual.unix_time,
|
|
|
|
markedUnread: Boolean(overrideProps.markedUnread),
|
|
|
|
membersCount: memberships.length,
|
|
|
|
memberships,
|
|
|
|
sharedGroupNames: [],
|
|
|
|
title: casual.title,
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId: generateAci(),
|
2022-11-19 08:31:18 +00:00
|
|
|
acknowledgedGroupNameCollisions: {},
|
|
|
|
storySendMode: StorySendMode.IfActive,
|
2022-08-10 18:37:19 +00:00
|
|
|
...overrideProps,
|
2022-11-19 08:31:18 +00:00
|
|
|
type: 'group' as const,
|
2022-08-10 18:37:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
export function getDefaultConversationWithServiceId(
|
2021-10-26 22:59:08 +00:00
|
|
|
overrideProps: Partial<ConversationType> = {},
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId: ServiceIdString = generateAci()
|
|
|
|
): ConversationType & { serviceId: ServiceIdString } {
|
2021-10-26 22:59:08 +00:00
|
|
|
return {
|
|
|
|
...getDefaultConversation(overrideProps),
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId,
|
2021-10-26 22:59:08 +00:00
|
|
|
};
|
|
|
|
}
|