Sync my stories with primary device

This commit is contained in:
Josh Perez 2022-06-30 20:52:03 -04:00 committed by GitHub
parent 7554d8326a
commit 9155784d56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
67 changed files with 2954 additions and 1238 deletions

View file

@ -0,0 +1,74 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { v4 as uuid } from 'uuid';
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';
import { MY_STORIES_ID } from '../../types/Stories';
function getAttachmentWithThumbnail(url: string): AttachmentType {
return fakeAttachment({
url,
thumbnail: fakeThumbnail(url),
});
}
export function getFakeMyStory(id?: string, name?: string): MyStoryType {
const storyCount = Math.ceil(Math.random() * 6 + 1);
return {
distributionId: id || uuid(),
distributionName:
name || id === MY_STORIES_ID ? 'My Stories' : 'Private Distribution List',
stories: Array.from(Array(storyCount), () => ({
...getFakeStoryView(),
sendState: [],
views: Math.floor(Math.random() * 20),
})),
};
}
export function getFakeStoryView(
attachmentUrl?: string,
timestamp?: number
): StoryViewType {
const sender = getDefaultConversation();
return {
attachment: getAttachmentWithThumbnail(
attachmentUrl || '/fixtures/tina-rolf-269345-unsplash.jpg'
),
hasReplies: Math.random() > 0.5,
isUnread: Math.random() > 0.5,
messageId: uuid(),
sender,
timestamp: timestamp || Date.now() - 2 * durations.MINUTE,
};
}
export function getFakeStory({
attachmentUrl,
group,
timestamp,
}: {
attachmentUrl?: string;
group?: ConversationType;
timestamp?: number;
}): ConversationStoryType {
const storyView = getFakeStoryView(attachmentUrl, timestamp);
return {
conversationId: storyView.sender.id,
group,
stories: [storyView],
};
}