2022-07-01 00:52:03 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-07-20 21:29:09 +00:00
|
|
|
import casual from 'casual';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
2022-07-01 00:52:03 +00:00
|
|
|
|
|
|
|
import type { AttachmentType } from '../../types/Attachment';
|
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
|
|
|
import type {
|
|
|
|
ConversationStoryType,
|
|
|
|
MyStoryType,
|
|
|
|
StoryViewType,
|
|
|
|
} from '../../types/Stories';
|
|
|
|
import * as durations from '../../util/durations';
|
|
|
|
import { getDefaultConversation } from './getDefaultConversation';
|
|
|
|
import { fakeAttachment, fakeThumbnail } from './fakeAttachment';
|
2022-11-16 22:10:11 +00:00
|
|
|
import { MY_STORY_ID, ResolvedSendStatus } from '../../types/Stories';
|
2022-07-01 00:52:03 +00:00
|
|
|
|
|
|
|
function getAttachmentWithThumbnail(url: string): AttachmentType {
|
|
|
|
return fakeAttachment({
|
2022-11-16 22:10:11 +00:00
|
|
|
path: url,
|
2022-07-01 00:52:03 +00:00
|
|
|
thumbnail: fakeThumbnail(url),
|
2022-11-16 22:10:11 +00:00
|
|
|
url,
|
2022-07-01 00:52:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFakeMyStory(id?: string, name?: string): MyStoryType {
|
2022-07-20 21:29:09 +00:00
|
|
|
const storyCount = casual.integer(2, 6);
|
2022-07-01 00:52:03 +00:00
|
|
|
|
|
|
|
return {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: id || generateUuid(),
|
2022-11-10 15:51:39 +00:00
|
|
|
name: name || id === MY_STORY_ID ? 'My Stories' : casual.catch_phrase,
|
2022-11-16 22:10:11 +00:00
|
|
|
reducedSendStatus: ResolvedSendStatus.Sent,
|
2022-07-01 00:52:03 +00:00
|
|
|
stories: Array.from(Array(storyCount), () => ({
|
|
|
|
...getFakeStoryView(),
|
|
|
|
sendState: [],
|
2022-07-20 21:29:09 +00:00
|
|
|
views: casual.integer(1, 20),
|
2022-07-01 00:52:03 +00:00
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFakeStoryView(
|
|
|
|
attachmentUrl?: string,
|
|
|
|
timestamp?: number
|
|
|
|
): StoryViewType {
|
|
|
|
const sender = getDefaultConversation();
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const messageId = generateUuid();
|
2022-10-03 23:10:20 +00:00
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
return {
|
|
|
|
attachment: getAttachmentWithThumbnail(
|
|
|
|
attachmentUrl || '/fixtures/tina-rolf-269345-unsplash.jpg'
|
|
|
|
),
|
2022-07-20 21:29:09 +00:00
|
|
|
isUnread: Boolean(casual.coin_flip),
|
2022-10-03 23:10:20 +00:00
|
|
|
messageId,
|
|
|
|
messageIdForLogging: `${messageId} (for logging)`,
|
2022-07-01 00:52:03 +00:00
|
|
|
sender,
|
|
|
|
timestamp: timestamp || Date.now() - 2 * durations.MINUTE,
|
2022-09-09 18:35:00 +00:00
|
|
|
expirationTimestamp: undefined,
|
2022-07-01 00:52:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFakeStory({
|
|
|
|
attachmentUrl,
|
|
|
|
group,
|
|
|
|
timestamp,
|
|
|
|
}: {
|
|
|
|
attachmentUrl?: string;
|
|
|
|
group?: ConversationType;
|
|
|
|
timestamp?: number;
|
|
|
|
}): ConversationStoryType {
|
|
|
|
const storyView = getFakeStoryView(attachmentUrl, timestamp);
|
|
|
|
|
2022-10-22 06:26:16 +00:00
|
|
|
const hasReplies = group ? Boolean(casual.coin_flip) : false;
|
|
|
|
const hasRepliesFromSelf =
|
|
|
|
group && hasReplies ? Boolean(casual.coin_flip) : false;
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
return {
|
|
|
|
conversationId: storyView.sender.id,
|
2022-10-22 06:26:16 +00:00
|
|
|
hasReplies,
|
|
|
|
hasRepliesFromSelf,
|
2022-07-01 00:52:03 +00:00
|
|
|
group,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyView,
|
2022-07-01 00:52:03 +00:00
|
|
|
};
|
|
|
|
}
|