diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 493211973..0c4b9f3fe 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -5244,7 +5244,7 @@ "description": "Label in confirmation modal to disable stories" }, "Preferences__turn-stories-off--body": { - "message": "You will no longer be able to share or view stories.", + "message": "You will no longer be able to share or view stories. Story updates you have recently shared will also be deleted.", "description": "Confirmation modal body for disabling stories" }, "DialogUpdate--version-available": { diff --git a/ts/main/settingsChannel.ts b/ts/main/settingsChannel.ts index 77a870f31..d640389e8 100644 --- a/ts/main/settingsChannel.ts +++ b/ts/main/settingsChannel.ts @@ -57,6 +57,7 @@ export class SettingsChannel extends EventEmitter { this.installCallback('getDefaultConversationColor'); // Various callbacks + this.installCallback('deleteAllMyStories'); this.installCallback('getAvailableIODevices'); this.installCallback('isPrimary'); this.installCallback('syncRequest'); diff --git a/ts/util/createIPCEvents.tsx b/ts/util/createIPCEvents.tsx index 645a1a745..65af476d4 100644 --- a/ts/util/createIPCEvents.tsx +++ b/ts/util/createIPCEvents.tsx @@ -41,6 +41,7 @@ import { } from './sgnlHref'; import { lookupConversationWithoutUuid } from './lookupConversationWithoutUuid'; import * as log from '../logging/log'; +import { deleteAllMyStories } from './deleteAllMyStories'; type ThemeType = 'light' | 'dark' | 'system'; type NotificationSettingType = 'message' | 'name' | 'count' | 'off'; @@ -94,6 +95,7 @@ export type IPCEventsCallbacksType = { addCustomColor: (customColor: CustomColorType) => void; addDarkOverlay: () => void; deleteAllData: () => Promise; + deleteAllMyStories: () => Promise; closeDB: () => Promise; editCustomColor: (colorId: string, customColor: CustomColorType) => void; getConversationsWithCustomColor: (x: string) => Array; @@ -205,6 +207,10 @@ export function createIPCEvents( setPreferredVideoInputDevice: device => window.storage.put('preferred-video-input-device', device), + deleteAllMyStories: async () => { + await deleteAllMyStories(); + }, + // Chat Color redux hookups getCustomColors: () => { return getCustomColors(window.reduxStore.getState()) || {}; diff --git a/ts/util/deleteAllMyStories.ts b/ts/util/deleteAllMyStories.ts new file mode 100644 index 000000000..5c0f0fceb --- /dev/null +++ b/ts/util/deleteAllMyStories.ts @@ -0,0 +1,15 @@ +// Copyright 2022 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { deleteStoryForEveryone } from './deleteStoryForEveryone'; + +export async function deleteAllMyStories(): Promise { + const { stories } = window.reduxStore.getState().stories; + const myStories = stories.filter(story => + Boolean(story.sendStateByConversationId) + ); + + await Promise.all( + myStories.map(story => deleteStoryForEveryone(stories, story)) + ); +} diff --git a/ts/windows/preload.ts b/ts/windows/preload.ts index eceb366f9..5f7dc5351 100644 --- a/ts/windows/preload.ts +++ b/ts/windows/preload.ts @@ -39,6 +39,7 @@ installSetting('typingIndicatorSetting', { setter: false, }); +installCallback('deleteAllMyStories'); installCallback('isPhoneNumberSharingEnabled'); installCallback('isPrimary'); installCallback('shouldShowStoriesSettings'); diff --git a/ts/windows/settings/preload.ts b/ts/windows/settings/preload.ts index 2c9db72df..194434cd7 100644 --- a/ts/windows/settings/preload.ts +++ b/ts/windows/settings/preload.ts @@ -88,6 +88,7 @@ const ipcPNP = createCallback('isPhoneNumberSharingEnabled'); const ipcShouldShowStoriesSettings = createCallback( 'shouldShowStoriesSettings' ); +const ipcDeleteAllMyStories = createCallback('deleteAllMyStories'); // ChatColorPicker redux hookups // The redux actions update over IPC through a preferences re-render @@ -301,7 +302,13 @@ const renderPreferences = async () => { onCountMutedConversationsChange: reRender( settingCountMutedConversations.setValue ), - onHasStoriesDisabledChanged: reRender(settingHasStoriesDisabled.setValue), + onHasStoriesDisabledChanged: reRender(async (value: boolean) => { + await settingHasStoriesDisabled.setValue(value); + if (!value) { + ipcDeleteAllMyStories(); + } + return value; + }), onHideMenuBarChange: reRender(settingHideMenuBar.setValue), onIncomingCallNotificationsChange: reRender( settingIncomingCallNotification.setValue