From 4a5da95c1d2307bab1f8b278553e6f71ca25b651 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:11:45 -0500 Subject: [PATCH] Fixes storybook --- ts/ConversationController.ts | 24 ++++-------------------- ts/background.ts | 1 + ts/components/Avatar.tsx | 2 +- ts/components/StoryListItem.tsx | 2 +- ts/services/storyLoader.ts | 2 +- ts/state/ducks/stories.ts | 2 +- ts/state/selectors/stories.ts | 2 +- ts/types/Conversation.ts | 4 ---- ts/types/SignalConversation.ts | 7 +++++++ ts/util/downloadOnboardingStory.ts | 1 + ts/util/isSignalConversation.ts | 2 +- 11 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 ts/types/SignalConversation.ts diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index 8f2b5b43fb80..eb4934989428 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -28,7 +28,7 @@ import { sleep } from './util/sleep'; import { isNotNil } from './util/isNotNil'; import { MINUTE, SECOND } from './util/durations'; import { getUuidsForE164s } from './util/getUuidsForE164s'; -import { SIGNAL_ACI, SIGNAL_AVATAR_PATH } from './types/Conversation'; +import { SIGNAL_ACI, SIGNAL_AVATAR_PATH } from './types/SignalConversation'; type ConvoMatchType = | { @@ -409,8 +409,8 @@ export class ConversationController { return conversation; } - getOrCreateSignalConversation(): ConversationModel { - const conversation = this.getOrCreate(SIGNAL_ACI, 'private', { + async getOrCreateSignalConversation(): Promise { + const conversation = await this.getOrCreateAndWait(SIGNAL_ACI, 'private', { muteExpiresAt: Number.MAX_SAFE_INTEGER, profileAvatar: { path: SIGNAL_AVATAR_PATH }, profileName: 'Signal', @@ -422,28 +422,12 @@ export class ConversationController { return conversation; } - getSignalConversationId(): string { - if (this._signalConversationId) { - return this._signalConversationId; - } - - let conversation = this.get(SIGNAL_ACI); - - if (!conversation) { - conversation = this.getOrCreateSignalConversation(); - } - - this._signalConversationId = conversation.id; - - return conversation.id; - } - isSignalConversation(uuidOrId: string): boolean { if (uuidOrId === SIGNAL_ACI) { return true; } - return this.getSignalConversationId() === uuidOrId; + return this._signalConversationId === uuidOrId; } areWePrimaryDevice(): boolean { diff --git a/ts/background.ts b/ts/background.ts index a0b9af048018..09be5364f1a8 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -1021,6 +1021,7 @@ export async function startApp(): Promise { await window.ConversationController.load(); await Promise.all([ + window.ConversationController.getOrCreateSignalConversation(), Stickers.load(), loadRecentEmojis(), loadInitialBadgesState(), diff --git a/ts/components/Avatar.tsx b/ts/components/Avatar.tsx index 13b7ba6c221f..6b254a505cc4 100644 --- a/ts/components/Avatar.tsx +++ b/ts/components/Avatar.tsx @@ -25,7 +25,7 @@ import { getBadgeImageFileLocalPath } from '../badges/getBadgeImageFileLocalPath import { getInitials } from '../util/getInitials'; import { isBadgeVisible } from '../badges/isBadgeVisible'; import { shouldBlurAvatar } from '../util/shouldBlurAvatar'; -import { SIGNAL_AVATAR_PATH } from '../types/Conversation'; +import { SIGNAL_AVATAR_PATH } from '../types/SignalConversation'; export enum AvatarBlur { NoBlur, diff --git a/ts/components/StoryListItem.tsx b/ts/components/StoryListItem.tsx index dd5ecfe2f071..f07da7112440 100644 --- a/ts/components/StoryListItem.tsx +++ b/ts/components/StoryListItem.tsx @@ -11,7 +11,7 @@ import type { ViewUserStoriesActionCreatorType } from '../state/ducks/stories'; import { Avatar, AvatarSize } from './Avatar'; import { ConfirmationDialog } from './ConfirmationDialog'; import { ContextMenu } from './ContextMenu'; -import { SIGNAL_ACI } from '../types/Conversation'; +import { SIGNAL_ACI } from '../types/SignalConversation'; import { StoryViewTargetType, HasStories } from '../types/Stories'; import { MessageTimestamp } from './conversation/MessageTimestamp'; diff --git a/ts/services/storyLoader.ts b/ts/services/storyLoader.ts index f285e6077a1e..93e5376c2db6 100644 --- a/ts/services/storyLoader.ts +++ b/ts/services/storyLoader.ts @@ -16,7 +16,7 @@ import { isNotNil } from '../util/isNotNil'; import { strictAssert } from '../util/assert'; import { dropNull } from '../util/dropNull'; import { isGroup } from '../util/whatTypeOfConversation'; -import { SIGNAL_ACI } from '../types/Conversation'; +import { SIGNAL_ACI } from '../types/SignalConversation'; let storyData: | Array< diff --git a/ts/state/ducks/stories.ts b/ts/state/ducks/stories.ts index b132bce03e59..11b36f0835a5 100644 --- a/ts/state/ducks/stories.ts +++ b/ts/state/ducks/stories.ts @@ -20,7 +20,7 @@ import type { StoryViewTargetType, StoryViewType } from '../../types/Stories'; import type { SyncType } from '../../jobs/helpers/syncHelpers'; import type { UUIDStringType } from '../../types/UUID'; import * as log from '../../logging/log'; -import { SIGNAL_ACI } from '../../types/Conversation'; +import { SIGNAL_ACI } from '../../types/SignalConversation'; import dataInterface from '../../sql/Client'; import { ReadStatus } from '../../messages/MessageReadStatus'; import { SafetyNumberChangeSource } from '../../components/SafetyNumberChangeDialog'; diff --git a/ts/state/selectors/stories.ts b/ts/state/selectors/stories.ts index 7ddb66fb8003..25c2a65bbc93 100644 --- a/ts/state/selectors/stories.ts +++ b/ts/state/selectors/stories.ts @@ -38,7 +38,7 @@ import { getStoriesEnabled } from './items'; import { calculateExpirationTimestamp } from '../../util/expirationTimer'; import { getMessageIdForLogging } from '../../util/idForLogging'; import * as log from '../../logging/log'; -import { SIGNAL_ACI } from '../../types/Conversation'; +import { SIGNAL_ACI } from '../../types/SignalConversation'; export const getStoriesState = (state: StateType): StoriesStateType => state.stories; diff --git a/ts/types/Conversation.ts b/ts/types/Conversation.ts index c350de8d31d0..29bc7755b4d6 100644 --- a/ts/types/Conversation.ts +++ b/ts/types/Conversation.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-only import type { ConversationAttributesType } from '../model-types.d'; -import { UUID } from './UUID'; import { computeHash } from '../Crypto'; export type BuildAvatarUpdaterOptions = Readonly<{ @@ -88,6 +87,3 @@ export async function deleteExternalFiles( await deleteAttachmentData(profileAvatar.path); } } - -export const SIGNAL_ACI = UUID.cast('11111111-1111-4111-8111-111111111111'); -export const SIGNAL_AVATAR_PATH = 'images/icon_256.png'; diff --git a/ts/types/SignalConversation.ts b/ts/types/SignalConversation.ts new file mode 100644 index 000000000000..0d62aa0d71bc --- /dev/null +++ b/ts/types/SignalConversation.ts @@ -0,0 +1,7 @@ +// Copyright 2022 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { UUID } from './UUID'; + +export const SIGNAL_ACI = UUID.cast('11111111-1111-4111-8111-111111111111'); +export const SIGNAL_AVATAR_PATH = 'images/icon_256.png'; diff --git a/ts/util/downloadOnboardingStory.ts b/ts/util/downloadOnboardingStory.ts index b422b58749f9..6ce82bc1cff5 100644 --- a/ts/util/downloadOnboardingStory.ts +++ b/ts/util/downloadOnboardingStory.ts @@ -92,6 +92,7 @@ async function continueDownloadingOnboardingStory(): Promise { }) ); + log.info('downloadOnboardingStory: getting signal conversation'); const signalConversation = await window.ConversationController.getOrCreateSignalConversation(); diff --git a/ts/util/isSignalConversation.ts b/ts/util/isSignalConversation.ts index ce709d4e394c..d3211174f062 100644 --- a/ts/util/isSignalConversation.ts +++ b/ts/util/isSignalConversation.ts @@ -1,7 +1,7 @@ // Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { SIGNAL_ACI } from '../types/Conversation'; +import { SIGNAL_ACI } from '../types/SignalConversation'; export function isSignalConversation(conversation: { id: string;