Sync storiesDisabled flag on AccountRecord

This commit is contained in:
Fedor Indutny 2022-10-04 10:53:36 -07:00 committed by GitHub
parent 3e57cb8549
commit 8b705d3b55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 35 deletions

View file

@ -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 {

View file

@ -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 },

View file

@ -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<boolean>;
onHasStoriesDisabledChanged: SelectChangeHandlerType<boolean>;
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 = ({
</label>
}
right={
hasStoriesEnabled ? (
hasStoriesDisabled ? (
<Button
onClick={() => onHasStoriesDisabledChanged(false)}
variant={ButtonVariant.Secondary}
>
{i18n('Preferences__turn-stories-on')}
</Button>
) : (
<Button
className="Preferences__stories-off"
onClick={() => setConfirmStoriesOff(true)}
@ -985,13 +992,6 @@ export const Preferences = ({
>
{i18n('Preferences__turn-stories-off')}
</Button>
) : (
<Button
onClick={() => onHasStoriesEnabledChanged(true)}
variant={ButtonVariant.Secondary}
>
{i18n('Preferences__turn-stories-on')}
</Button>
)
}
/>
@ -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'),
},

View file

@ -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 });

View file

@ -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<ConversationModel>();
@ -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();

View file

@ -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'))
);

View file

@ -1904,7 +1904,7 @@ export default class MessageReceiver
const attachments: Array<ProcessedAttachment> = [];
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'
);

View file

@ -67,7 +67,7 @@ export type StorageAccessType = {
device_name: string;
hasRegisterSupportForUnauthenticatedDelivery: boolean;
hasSetMyStoriesPrivacy: boolean;
hasStoriesEnabled: boolean;
hasStoriesDisabled: boolean;
identityKeyMap: IdentityKeyMap;
lastHeartbeat: number;
lastStartup: number;

View file

@ -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

View file

@ -52,7 +52,7 @@ installSetting('callRingtoneNotification');
installSetting('callSystemNotification');
installSetting('countMutedConversations');
installSetting('deviceName');
installSetting('hasStoriesEnabled');
installSetting('hasStoriesDisabled');
installSetting('hideMenuBar');
installSetting('incomingCallNotification');
installSetting('lastSyncTime');

View file

@ -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