From 0a7384c1f442747d9e8296dd67b0ed9be7c2f845 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 27 Feb 2025 10:52:56 +1100 Subject: [PATCH] fix: show account created :tada: emoji until we open a conversation --- ts/components/EmptyMessageView.tsx | 5 +++-- ts/components/SessionInboxView.tsx | 22 +++++++++++++++------- ts/data/settings-key.ts | 2 ++ ts/state/ducks/conversations.ts | 6 ++++++ ts/state/ducks/settings.tsx | 5 +++++ ts/state/selectors/settings.ts | 9 +++++++++ ts/util/storage.ts | 8 ++++---- 7 files changed, 44 insertions(+), 13 deletions(-) diff --git a/ts/components/EmptyMessageView.tsx b/ts/components/EmptyMessageView.tsx index d9e60adea..8a37e6d9c 100644 --- a/ts/components/EmptyMessageView.tsx +++ b/ts/components/EmptyMessageView.tsx @@ -6,6 +6,7 @@ import { isSignWithRecoveryPhrase } from '../util/storage'; import { Flex } from './basic/Flex'; import { Spacer2XL, SpacerXS } from './basic/Text'; import { Localizer } from './basic/Localizer'; +import { useShowOnboardingAccountJustCreated } from '../state/selectors/settings'; const StyledPlaceholder = styled(Flex)` background-color: var(--background-secondary-color); @@ -72,8 +73,8 @@ export const EmptyMessageView = () => { const conversationCount = useSelector(getLeftPaneConversationIdsCount); const isSignInWithRecoveryPhrase = isSignWithRecoveryPhrase(); - const launchCount = window.getSettingValue('launch-count'); - const newAccountCreated = !isSignInWithRecoveryPhrase && (!launchCount || launchCount < 1); + const showOnboardingAccountJustCreated = useShowOnboardingAccountJustCreated(); + const newAccountCreated = !isSignInWithRecoveryPhrase && showOnboardingAccountJustCreated; return ( void) { window.inboxStore?.dispatch( updateAllOnStorageReady({ - hasBlindedMsgRequestsEnabled: Storage.getBoolOrFalse( - SettingsKey.hasBlindedMsgRequestsEnabled + hasBlindedMsgRequestsEnabled: Storage.getBoolOr( + SettingsKey.hasBlindedMsgRequestsEnabled, + false + ), + someDeviceOutdatedSyncing: Storage.getBoolOr(SettingsKey.someDeviceOutdatedSyncing, false), + settingsLinkPreview: Storage.getBoolOr(SettingsKey.settingsLinkPreview, false), + hasFollowSystemThemeEnabled: Storage.getBoolOr( + SettingsKey.hasFollowSystemThemeEnabled, + false + ), + hasShiftSendEnabled: Storage.getBoolOr(SettingsKey.hasShiftSendEnabled, false), + hideRecoveryPassword: Storage.getBoolOr(SettingsKey.hideRecoveryPassword, false), + showOnboardingAccountJustCreated: Storage.getBoolOr( + SettingsKey.showOnboardingAccountJustCreated, + true ), - someDeviceOutdatedSyncing: Storage.getBoolOrFalse(SettingsKey.someDeviceOutdatedSyncing), - settingsLinkPreview: Storage.getBoolOrFalse(SettingsKey.settingsLinkPreview), - hasFollowSystemThemeEnabled: Storage.getBoolOrFalse(SettingsKey.hasFollowSystemThemeEnabled), - hasShiftSendEnabled: Storage.getBoolOrFalse(SettingsKey.hasShiftSendEnabled), - hideRecoveryPassword: Storage.getBoolOrFalse(SettingsKey.hideRecoveryPassword), }) ); window.inboxStore?.dispatch(groupInfoActions.loadMetaDumpsFromDB() as any); // this loads the dumps from DB and fills the 03-groups slice with the corresponding details diff --git a/ts/data/settings-key.ts b/ts/data/settings-key.ts index ee08ff535..93522b4ff 100644 --- a/ts/data/settings-key.ts +++ b/ts/data/settings-key.ts @@ -21,6 +21,7 @@ const hideRecoveryPassword = 'hideRecoveryPassword'; const latestUserProfileEnvelopeTimestamp = 'latestUserProfileEnvelopeTimestamp'; const latestUserGroupEnvelopeTimestamp = 'latestUserGroupEnvelopeTimestamp'; const latestUserContactsEnvelopeTimestamp = 'latestUserContactsEnvelopeTimestamp'; +const showOnboardingAccountJustCreated = 'showOnboardingAccountJustCreated'; export const SettingsKey = { settingsReadReceipt, @@ -44,6 +45,7 @@ export const SettingsKey = { latestUserContactsEnvelopeTimestamp, hasFollowSystemThemeEnabled, hideRecoveryPassword, + showOnboardingAccountJustCreated, } as const; export const KNOWN_BLINDED_KEYS_ITEM = 'KNOWN_BLINDED_KEYS_ITEM'; diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 99f9a85aa..aab9113cc 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -28,6 +28,8 @@ import { CONVERSATION_PRIORITIES, ConversationTypeEnum } from '../../models/type import { WithConvoId, WithMessageHash, WithMessageId } from '../../session/types/with'; import { cancelUpdatesToDispatch } from '../../models/message'; import type { SessionSuggestionDataItem } from '../../components/conversation/composition/types'; +import { Storage } from '../../util/storage'; +import { SettingsKey } from '../../data/settings-key'; export type MessageModelPropsWithoutConvoProps = { propsForMessage: PropsForMessageWithoutConvoProps; @@ -1107,6 +1109,10 @@ export async function openConversationWithMessages(args: { }) { const { conversationKey, messageId } = args; + if (Storage.getBoolOr(SettingsKey.showOnboardingAccountJustCreated, true)) { + await Storage.put(SettingsKey.showOnboardingAccountJustCreated, false); + } + await DisappearingMessages.destroyExpiredMessages(); await unmarkAsForcedUnread(conversationKey); diff --git a/ts/state/ducks/settings.tsx b/ts/state/ducks/settings.tsx index a231606ab..52b505a97 100644 --- a/ts/state/ducks/settings.tsx +++ b/ts/state/ducks/settings.tsx @@ -10,6 +10,7 @@ const SettingsBoolsKeyTrackedInRedux = [ SettingsKey.hasFollowSystemThemeEnabled, SettingsKey.hasShiftSendEnabled, SettingsKey.hideRecoveryPassword, + SettingsKey.showOnboardingAccountJustCreated, ] as const; export type SettingsState = { @@ -25,6 +26,7 @@ export function getSettingsInitialState() { hasFollowSystemThemeEnabled: false, hasShiftSendEnabled: false, hideRecoveryPassword: false, + showOnboardingAccountJustCreated: true, }, }; } @@ -56,6 +58,7 @@ const settingsSlice = createSlice({ hasFollowSystemThemeEnabled: boolean; hasShiftSendEnabled: boolean; hideRecoveryPassword: boolean; + showOnboardingAccountJustCreated: boolean; }> ) { const { @@ -65,6 +68,7 @@ const settingsSlice = createSlice({ someDeviceOutdatedSyncing, hasShiftSendEnabled, hideRecoveryPassword, + showOnboardingAccountJustCreated, } = payload; state.settingsBools.someDeviceOutdatedSyncing = someDeviceOutdatedSyncing; @@ -73,6 +77,7 @@ const settingsSlice = createSlice({ state.settingsBools.hasFollowSystemThemeEnabled = hasFollowSystemThemeEnabled; state.settingsBools.hasShiftSendEnabled = hasShiftSendEnabled; state.settingsBools.hideRecoveryPassword = hideRecoveryPassword; + state.settingsBools.showOnboardingAccountJustCreated = showOnboardingAccountJustCreated; return state; }, diff --git a/ts/state/selectors/settings.ts b/ts/state/selectors/settings.ts index 9137a3ec3..2c0f21ca3 100644 --- a/ts/state/selectors/settings.ts +++ b/ts/state/selectors/settings.ts @@ -20,6 +20,9 @@ const getHasShiftSendEnabled = (state: StateType) => const getHideRecoveryPassword = (state: StateType) => state.settings.settingsBools[SettingsKey.hideRecoveryPassword]; +const getShowOnboardingAccountJustCreated = (state: StateType) => + state.settings.settingsBools[SettingsKey.showOnboardingAccountJustCreated]; + export const useHasLinkPreviewEnabled = () => { const value = useSelector(getLinkPreviewEnabled); return Boolean(value); @@ -51,3 +54,9 @@ export const useHideRecoveryPasswordEnabled = () => { return Boolean(value); }; + +export const useShowOnboardingAccountJustCreated = () => { + const value = useSelector(getShowOnboardingAccountJustCreated); + + return Boolean(value); +}; diff --git a/ts/util/storage.ts b/ts/util/storage.ts index ad8800d32..de47b9ae5 100644 --- a/ts/util/storage.ts +++ b/ts/util/storage.ts @@ -93,12 +93,12 @@ function reset() { items = Object.create(null); } -function getBoolOrFalse(settingsKey: string): boolean { - const got = Storage.get(settingsKey, false); +function getBoolOr(settingsKey: string, fallback: boolean): boolean { + const got = Storage.get(settingsKey, fallback); if (isBoolean(got)) { return got; } - return false; + return fallback; } export async function setLocalPubKey(pubkey: string) { @@ -171,4 +171,4 @@ export function getPasswordHash() { return Storage.get('passHash') as string; } -export const Storage = { fetch, put, get, getBoolOrFalse, remove, onready, reset }; +export const Storage = { fetch, put, get, getBoolOr, remove, onready, reset };