From 8b705d3b55b4a96106023bb1c79c4db98275ddf7 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:53:36 -0700 Subject: [PATCH] Sync `storiesDisabled` flag on AccountRecord --- protos/SignalStorage.proto | 2 ++ ts/components/Preferences.stories.tsx | 4 ++-- ts/components/Preferences.tsx | 26 +++++++++++++------------- ts/main/settingsChannel.ts | 2 +- ts/services/storageRecordOps.ts | 5 +++++ ts/state/selectors/items.ts | 2 +- ts/textsecure/MessageReceiver.ts | 4 ++-- ts/types/Storage.d.ts | 2 +- ts/util/createIPCEvents.tsx | 18 +++++++++--------- ts/windows/preload.ts | 2 +- ts/windows/settings/preload.ts | 10 +++++----- 11 files changed, 42 insertions(+), 35 deletions(-) diff --git a/protos/SignalStorage.proto b/protos/SignalStorage.proto index 43cf7370f3b..68bc3325b64 100644 --- a/protos/SignalStorage.proto +++ b/protos/SignalStorage.proto @@ -155,6 +155,8 @@ message AccountRecord { optional bool displayBadgesOnProfile = 23; optional bool keepMutedChatsArchived = 25; optional bool hasSetMyStoriesPrivacy = 26; + reserved /* hasViewedOnboardingStory */ 27; + optional bool storiesDisabled = 28; } message StoryDistributionListRecord { diff --git a/ts/components/Preferences.stories.tsx b/ts/components/Preferences.stories.tsx index 5cdeba7fbb4..b9a50bbcde7 100644 --- a/ts/components/Preferences.stories.tsx +++ b/ts/components/Preferences.stories.tsx @@ -87,7 +87,7 @@ const getDefaultArgs = (): PropsDataType => ({ hasReadReceipts: true, hasRelayCalls: false, hasSpellCheck: true, - hasStoriesEnabled: true, + hasStoriesDisabled: false, hasTypingIndicators: true, initialSpellCheckSetting: true, isAudioNotificationsSupported: true, @@ -142,7 +142,7 @@ export default { onCallNotificationsChange: { action: true }, onCallRingtoneNotificationChange: { action: true }, onCountMutedConversationsChange: { action: true }, - onHasStoriesEnabledChanged: { action: true }, + onHasStoriesDisabledChanged: { action: true }, onHideMenuBarChange: { action: true }, onIncomingCallNotificationsChange: { action: true }, onLastSyncTimeChange: { action: true }, diff --git a/ts/components/Preferences.tsx b/ts/components/Preferences.tsx index fb554bcd762..ae5e7393d97 100644 --- a/ts/components/Preferences.tsx +++ b/ts/components/Preferences.tsx @@ -68,7 +68,7 @@ export type PropsDataType = { hasReadReceipts: boolean; hasRelayCalls?: boolean; hasSpellCheck: boolean; - hasStoriesEnabled: boolean; + hasStoriesDisabled: boolean; hasTypingIndicators: boolean; lastSyncTime?: number; notificationContent: NotificationSettingType; @@ -133,7 +133,7 @@ type PropsFunctionType = { onCallNotificationsChange: CheckboxChangeHandlerType; onCallRingtoneNotificationChange: CheckboxChangeHandlerType; onCountMutedConversationsChange: CheckboxChangeHandlerType; - onHasStoriesEnabledChanged: SelectChangeHandlerType; + onHasStoriesDisabledChanged: SelectChangeHandlerType; onHideMenuBarChange: CheckboxChangeHandlerType; onIncomingCallNotificationsChange: CheckboxChangeHandlerType; onLastSyncTimeChange: (time: number) => unknown; @@ -228,7 +228,7 @@ export const Preferences = ({ hasReadReceipts, hasRelayCalls, hasSpellCheck, - hasStoriesEnabled, + hasStoriesDisabled, hasTypingIndicators, i18n, initialSpellCheckSetting, @@ -251,7 +251,7 @@ export const Preferences = ({ onCallNotificationsChange, onCallRingtoneNotificationChange, onCountMutedConversationsChange, - onHasStoriesEnabledChanged, + onHasStoriesDisabledChanged, onHideMenuBarChange, onIncomingCallNotificationsChange, onLastSyncTimeChange, @@ -977,7 +977,14 @@ export const Preferences = ({ } right={ - hasStoriesEnabled ? ( + hasStoriesDisabled ? ( + + ) : ( - ) : ( - ) } /> @@ -1043,7 +1043,7 @@ export const Preferences = ({ dialogName="Preference.turnStoriesOff" actions={[ { - action: () => onHasStoriesEnabledChanged(false), + action: () => onHasStoriesDisabledChanged(true), style: 'negative', text: i18n('Preferences__turn-stories-off--action'), }, diff --git a/ts/main/settingsChannel.ts b/ts/main/settingsChannel.ts index 64255617708..77a870f3104 100644 --- a/ts/main/settingsChannel.ts +++ b/ts/main/settingsChannel.ts @@ -104,7 +104,7 @@ export class SettingsChannel extends EventEmitter { this.installSetting('lastSyncTime'); this.installSetting('universalExpireTimer'); - this.installSetting('hasStoriesEnabled'); + this.installSetting('hasStoriesDisabled'); this.installSetting('zoomFactor'); installPermissionsHandler({ session, userConfig }); diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index 358603e1934..2de9368048f 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -359,6 +359,9 @@ export function toAccountRecord( accountRecord.hasSetMyStoriesPrivacy = hasSetMyStoriesPrivacy; } + const hasStoriesDisabled = window.storage.get('hasStoriesDisabled'); + accountRecord.storiesDisabled = hasStoriesDisabled === true; + applyUnknownFields(accountRecord, conversation); return accountRecord; @@ -1059,6 +1062,7 @@ export async function mergeAccountRecord( displayBadgesOnProfile, keepMutedChatsArchived, hasSetMyStoriesPrivacy, + storiesDisabled, } = accountRecord; const updatedConversations = new Array(); @@ -1252,6 +1256,7 @@ export async function mergeAccountRecord( window.storage.put('displayBadgesOnProfile', Boolean(displayBadgesOnProfile)); window.storage.put('keepMutedChatsArchived', Boolean(keepMutedChatsArchived)); window.storage.put('hasSetMyStoriesPrivacy', Boolean(hasSetMyStoriesPrivacy)); + window.storage.put('hasStoriesDisabled', Boolean(storiesDisabled)); const ourID = window.ConversationController.getOurConversationId(); diff --git a/ts/state/selectors/items.ts b/ts/state/selectors/items.ts index c8a444e80bc..61333227b11 100644 --- a/ts/state/selectors/items.ts +++ b/ts/state/selectors/items.ts @@ -67,7 +67,7 @@ export const getStoriesEnabled = createSelector( getItems, getRemoteConfig, (state: ItemsStateType, remoteConfig: ConfigMapType): boolean => - state.hasStoriesEnabled !== false && + !state.hasStoriesDisabled && (isRemoteConfigFlagEnabled(remoteConfig, 'desktop.internalUser') || isRemoteConfigFlagEnabled(remoteConfig, 'desktop.stories')) ); diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 783c473dd1c..a405184d7f2 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -1904,7 +1904,7 @@ export default class MessageReceiver const attachments: Array = []; - if (!window.Events.getHasStoriesEnabled()) { + if (window.Events.getHasStoriesDisabled()) { log.info('MessageReceiver.handleStoryMessage: dropping', logId); this.removeFromCache(envelope); return; @@ -2697,7 +2697,7 @@ export default class MessageReceiver } if (sentMessage.storyMessageRecipients && sentMessage.isRecipientUpdate) { - if (!window.Events.getHasStoriesEnabled()) { + if (window.Events.getHasStoriesDisabled()) { log.info( 'MessageReceiver.handleSyncMessage: dropping story recipients update' ); diff --git a/ts/types/Storage.d.ts b/ts/types/Storage.d.ts index 3ee8486710e..f6edbb435a4 100644 --- a/ts/types/Storage.d.ts +++ b/ts/types/Storage.d.ts @@ -67,7 +67,7 @@ export type StorageAccessType = { device_name: string; hasRegisterSupportForUnauthenticatedDelivery: boolean; hasSetMyStoriesPrivacy: boolean; - hasStoriesEnabled: boolean; + hasStoriesDisabled: boolean; identityKeyMap: IdentityKeyMap; lastHeartbeat: number; lastStartup: number; diff --git a/ts/util/createIPCEvents.tsx b/ts/util/createIPCEvents.tsx index b8f56162104..c138e6ebe34 100644 --- a/ts/util/createIPCEvents.tsx +++ b/ts/util/createIPCEvents.tsx @@ -48,7 +48,7 @@ export type IPCEventsValuesType = { callRingtoneNotification: boolean; callSystemNotification: boolean; countMutedConversations: boolean; - hasStoriesEnabled: boolean; + hasStoriesDisabled: boolean; hideMenuBar: boolean | undefined; incomingCallNotification: boolean; lastSyncTime: number | undefined; @@ -178,9 +178,13 @@ export function createIPCEvents( webFrame.setZoomFactor(zoomFactor); }, - getHasStoriesEnabled: () => window.storage.get('hasStoriesEnabled', true), - setHasStoriesEnabled: (value: boolean) => - window.storage.put('hasStoriesEnabled', value), + getHasStoriesDisabled: () => + window.storage.get('hasStoriesDisabled', false), + setHasStoriesDisabled: async (value: boolean) => { + await window.storage.put('hasStoriesDisabled', value); + const account = window.ConversationController.getOurConversationOrThrow(); + account.captureChange('hasStoriesDisabled'); + }, getPreferredAudioInputDevice: () => window.storage.get('preferred-audio-input-device'), @@ -357,11 +361,7 @@ export function createIPCEvents( await universalExpireTimer.set(newValue); // Update account in Storage Service - const conversationId = - window.ConversationController.getOurConversationIdOrThrow(); - const account = window.ConversationController.get(conversationId); - assertDev(account, "Account wasn't found"); - + const account = window.ConversationController.getOurConversationOrThrow(); account.captureChange('universalExpireTimer'); // Add a notification to the currently open conversation diff --git a/ts/windows/preload.ts b/ts/windows/preload.ts index 2a66e2afcef..eceb366f91e 100644 --- a/ts/windows/preload.ts +++ b/ts/windows/preload.ts @@ -52,7 +52,7 @@ installSetting('callRingtoneNotification'); installSetting('callSystemNotification'); installSetting('countMutedConversations'); installSetting('deviceName'); -installSetting('hasStoriesEnabled'); +installSetting('hasStoriesDisabled'); installSetting('hideMenuBar'); installSetting('incomingCallNotification'); installSetting('lastSyncTime'); diff --git a/ts/windows/settings/preload.ts b/ts/windows/settings/preload.ts index 4c65950d4a7..2c9db72dfa0 100644 --- a/ts/windows/settings/preload.ts +++ b/ts/windows/settings/preload.ts @@ -50,7 +50,7 @@ const settingSystemTraySetting = createSetting('systemTraySetting'); const settingLastSyncTime = createSetting('lastSyncTime'); -const settingHasStoriesEnabled = createSetting('hasStoriesEnabled'); +const settingHasStoriesDisabled = createSetting('hasStoriesDisabled'); const settingZoomFactor = createSetting('zoomFactor'); // Getters only. @@ -150,7 +150,7 @@ const renderPreferences = async () => { hasReadReceipts, hasRelayCalls, hasSpellCheck, - hasStoriesEnabled, + hasStoriesDisabled, hasTypingIndicators, isPhoneNumberSharingSupported, lastSyncTime, @@ -188,7 +188,7 @@ const renderPreferences = async () => { hasReadReceipts: settingReadReceipts.getValue(), hasRelayCalls: settingRelayCalls.getValue(), hasSpellCheck: settingSpellCheck.getValue(), - hasStoriesEnabled: settingHasStoriesEnabled.getValue(), + hasStoriesDisabled: settingHasStoriesDisabled.getValue(), hasTypingIndicators: settingTypingIndicators.getValue(), isPhoneNumberSharingSupported: ipcPNP(), lastSyncTime: settingLastSyncTime.getValue(), @@ -244,7 +244,7 @@ const renderPreferences = async () => { hasReadReceipts, hasRelayCalls, hasSpellCheck, - hasStoriesEnabled, + hasStoriesDisabled, hasTypingIndicators, lastSyncTime, notificationContent, @@ -301,7 +301,7 @@ const renderPreferences = async () => { onCountMutedConversationsChange: reRender( settingCountMutedConversations.setValue ), - onHasStoriesEnabledChanged: reRender(settingHasStoriesEnabled.setValue), + onHasStoriesDisabledChanged: reRender(settingHasStoriesDisabled.setValue), onHideMenuBarChange: reRender(settingHideMenuBar.setValue), onIncomingCallNotificationsChange: reRender( settingIncomingCallNotification.setValue