From 5c1f9cec954a1585b9dfd6dc0dd84cc997f259e3 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Thu, 18 Jan 2024 18:11:48 +0100 Subject: [PATCH] feat: add modal for catching feature changes --- src/i18n/en-US.json | 5 ++- .../FeatureConfigChangeNotifier.ts | 38 ++++++++++++++++++- src/script/team/TeamRepository.ts | 4 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/i18n/en-US.json b/src/i18n/en-US.json index a186d4d8a5d..686c83ad1cd 100644 --- a/src/i18n/en-US.json +++ b/src/i18n/en-US.json @@ -630,6 +630,9 @@ "featureConfigChangeModalAudioVideoDescriptionItemCameraDisabled": "Camera in calls is disabled", "featureConfigChangeModalAudioVideoDescriptionItemCameraEnabled": "Camera in calls is enabled", "featureConfigChangeModalAudioVideoHeadline": "There has been a change in {{brandName}}", + "featureConfigChangeModalDownloadPathDisabled": "Enforced Download Path is disabled. You will need to restart the app if you want to save downloads in a new location.", + "featureConfigChangeModalDownloadPathEnabled": "Enforced Download Path is enabled. The App will restart for the new settings to take effect.", + "featureConfigChangeModalDownloadPathHeadline": "There has been a change in {{brandName}}", "featureConfigChangeModalConferenceCallingEnabled": "Your team was upgraded to {{brandName}} Enterprise, which gives you access to features such as conference calls and more. [link]Learn more about {{brandName}} Enterprise[/link]", "featureConfigChangeModalConferenceCallingTitle": "{{brandName}} Enterprise", "featureConfigChangeModalConversationGuestLinksDescriptionItemConversationGuestLinksDisabled": "Generating guest links is now disabled for all group admins.", @@ -1506,4 +1509,4 @@ "wireMacos": "{{brandName}} for macOS", "wireWindows": "{{brandName}} for Windows", "wire_for_web": "{{brandName}} for Web" -} +} \ No newline at end of file diff --git a/src/script/page/components/FeatureConfigChange/FeatureConfigChangeNotifier/FeatureConfigChangeNotifier.ts b/src/script/page/components/FeatureConfigChange/FeatureConfigChangeNotifier/FeatureConfigChangeNotifier.ts index 3a3930b674c..b0c81f3e14c 100644 --- a/src/script/page/components/FeatureConfigChange/FeatureConfigChangeNotifier/FeatureConfigChangeNotifier.ts +++ b/src/script/page/components/FeatureConfigChange/FeatureConfigChangeNotifier/FeatureConfigChangeNotifier.ts @@ -27,8 +27,13 @@ import { FeatureStatus, SelfDeletingTimeout, } from '@wireapp/api-client/lib/team/feature/'; +import {amplify} from 'amplify'; + +import {Runtime} from '@wireapp/commons'; +import {WebAppEvents} from '@wireapp/webapp-events'; import {PrimaryModal} from 'Components/Modals/PrimaryModal'; +import {Action} from 'Components/Modals/PrimaryModal/PrimaryModalTypes'; import {useKoSubscribableChildren} from 'Util/ComponentUtil'; import {StringIdentifer, replaceLink, t} from 'Util/LocalizerUtil'; import {getLogger} from 'Util/Logger'; @@ -44,8 +49,8 @@ const featureNotifications: Partial< FEATURE_KEY, ( oldConfig?: Feature | FeatureWithoutConfig, - newConfig?: Feature | FeatureWithoutConfig, - ) => undefined | {htmlMessage: string; title: StringIdentifer} + newConfig?: FeatureWithoutConfig | Feature | undefined, + ) => undefined | {htmlMessage: string; title: StringIdentifer; primaryAction?: Action} > > = { [FEATURE_KEY.FILE_SHARING]: (oldConfig, newConfig) => { @@ -74,6 +79,33 @@ const featureNotifications: Partial< title: 'featureConfigChangeModalAudioVideoHeadline', }; }, + [FEATURE_KEY.ENFORCE_DOWNLOAD_PATH]: (oldConfig, newConfig) => { + const status = wasTurnedOnOrOff(oldConfig, newConfig); + if (!status) { + return undefined; + } + if (newConfig && 'config' in newConfig) { + amplify.publish( + WebAppEvents.TEAM.DOWNLOAD_PATH_UPDATE, + newConfig.status === FeatureStatus.ENABLED ? newConfig.config.enforcedDownloadLocation : undefined, + ); + } + return { + htmlMessage: + status === FeatureStatus.ENABLED + ? t('featureConfigChangeModalDownloadPathEnabled') + : t('featureConfigChangeModalDownloadPathDisabled'), + title: 'featureConfigChangeModalDownloadPathHeadline', + primaryAction: { + action: () => { + if (Runtime.isDesktopApp() && status === FeatureStatus.ENABLED) { + // if we are in a desktop env, we just warn the wrapper that we need to reload. It then decide what should be done + amplify.publish(WebAppEvents.LIFECYCLE.RESTART); + } + }, + }, + }; + }, [FEATURE_KEY.SELF_DELETING_MESSAGES]: (oldConfig, newConfig) => { if (!oldConfig || !('config' in oldConfig) || !newConfig || !('config' in newConfig)) { return undefined; @@ -181,6 +213,8 @@ export function FeatureConfigChangeNotifier({teamState, selfUserId}: Props): nul brandName: Config.getConfig().BRAND_NAME, }), }, + primaryAction: message.primaryAction, + hideCloseBtn: featureKey === FEATURE_KEY.ENFORCE_DOWNLOAD_PATH, }); }); } diff --git a/src/script/team/TeamRepository.ts b/src/script/team/TeamRepository.ts index 4722acf26a7..e9c7117be78 100644 --- a/src/script/team/TeamRepository.ts +++ b/src/script/team/TeamRepository.ts @@ -29,7 +29,7 @@ import type { TeamUpdateEvent, } from '@wireapp/api-client/lib/event'; import {TEAM_EVENT} from '@wireapp/api-client/lib/event/TeamEvent'; -import {FeatureStatus, FeatureList, FEATURE_KEY} from '@wireapp/api-client/lib/team/feature/'; +import {FeatureStatus, FeatureList} from '@wireapp/api-client/lib/team/feature/'; import type {PermissionsData} from '@wireapp/api-client/lib/team/member/PermissionsData'; import type {TeamData} from '@wireapp/api-client/lib/team/team/TeamData'; import {QualifiedId} from '@wireapp/api-client/lib/user'; @@ -401,7 +401,7 @@ export class TeamRepository extends TypedEventEmitter { event: TeamFeatureConfigurationUpdateEvent, source: EventSource, ): Promise => { - if (source !== EventSource.WEBSOCKET && event.name !== FEATURE_KEY.ENFORCE_DOWNLOAD_PATH) { + if (source !== EventSource.WEBSOCKET) { // Ignore notification stream events return; }