Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(system-wide-user-notification): show a notification configured in config.js (#17946)
Дамян Минковb576a7f6077d
diff --git a/config.js b/config.jsindex 28503f02e5..032f58a669 100644--- a/config.js+++ b/config.js@@ -1937,6 +1937,26 @@ var config = {// List of notifications to be disabled. Works in tandem with the above setting.// disabledNotifications: [],+ // A notification shown to every user, with a button which opens a link. It is shown when the user joins a+ // meeting, until the user clicks "Don't show again", and on the welcome page.+ // systemWideUserNotification: {+ // // Identifies the notification. The users who chose not to see it again see it again when the id changes.+ // // Defaults to the url.+ // id: 'announcement-1',+ // // The link opened by the button.+ // url: 'https://example.com/announcement',+ // // The texts, by language code. A missing language or text falls back to English. The button and+ // // dontShowAgain texts have defaults.+ // labels: {+ // en: {+ // title: 'Things are changing',+ // description: 'Read about what is new.',+ // button: 'Learn more',+ // dontShowAgain: 'Don\'t show again',+ // },+ // },+ // },+// filmstrip: {// // Disable the vertical/horizontal filmstrip.// disabled: false,diff --git a/css/_welcome_page.scss b/css/_welcome_page.scssindex e6188e047d..edac71ff70 100644--- a/css/_welcome_page.scss+++ b/css/_welcome_page.scss@@ -314,6 +314,35 @@ body.welcome-page {&--grey {background: #F2F3F4;}++ &--notification {+ background: #444447;+ border-left: 4px solid #0163FF;+ box-sizing: border-box;+ color: #fff;+ padding: 24px 32px;+ }+ }++ .welcome-notification-title {+ color: #fff;+ font-size: 20px;+ font-weight: 600;+ line-height: 28px;+ margin: 0;+ }++ .welcome-notification-description {+ font-size: 16px;+ line-height: 24px;+ margin: 8px 0;+ }++ .welcome-notification-link {+ color: #4C9AFF;+ font-size: 16px;+ font-weight: 600;+ text-decoration: underline;}.welcome-footer {diff --git a/lang/main.json b/lang/main.jsonindex b45988c600..ec98415da7 100644--- a/lang/main.json+++ b/lang/main.json@@ -1406,6 +1406,10 @@"text": "Press the <i>Rejoin</i> button to reconnect.","title": "Your video call was interrupted because this computer went to sleep."},+ "systemWideUserNotification": {+ "button": "Learn more",+ "dontShowAgain": "Don't show again"+ },"termsView": {"title": "Terms"},diff --git a/react/features/app/middlewares.any.ts b/react/features/app/middlewares.any.tsindex 3acb192b3d..f09fca773b 100644--- a/react/features/app/middlewares.any.ts+++ b/react/features/app/middlewares.any.ts@@ -48,6 +48,7 @@ import '../room-lock/middleware';import '../rtcstats/middleware';import '../speaker-stats/middleware';import '../subtitles/middleware';+import '../system-wide-user-notification/middleware';import '../time-timer/middleware';import '../transcribing/middleware';import '../video-layout/middleware';diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex dd89297db9..c1d25b2052 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -1,3 +1,4 @@+import { ISystemWideUserNotificationConfig } from '../../system-wide-user-notification/types';import { ToolbarButton } from '../../toolbox/types';import { ILoggingConfig } from '../logging/types';import { IAudioSettings } from '../settings/reducer';@@ -732,6 +733,7 @@ export interface IConfig {startWithVideoMuted?: boolean;stereo?: boolean;subject?: string;+ systemWideUserNotification?: ISystemWideUserNotificationConfig;testing?: {assumeBandwidth?: boolean;debugAudioLevels?: boolean;diff --git a/react/features/system-wide-user-notification/components/web/WelcomePageNotification.tsx b/react/features/system-wide-user-notification/components/web/WelcomePageNotification.tsxnew file mode 100644index 0000000000..683c8c55b5--- /dev/null+++ b/react/features/system-wide-user-notification/components/web/WelcomePageNotification.tsx@@ -0,0 +1,37 @@+import React from 'react';+import { useTranslation } from 'react-i18next';+import { useSelector } from 'react-redux';++import { getSystemWideUserNotification, getTextKeys } from '../../functions';++/**+ * Shows the system-wide user notification on the welcome page.+ *+ * @returns {ReactElement|null}+ */+const WelcomePageNotification = () => {+ const { t } = useTranslation();+ const config = useSelector(getSystemWideUserNotification);++ if (!config?.url) {+ return null;+ }++ const { buttonKey, descriptionKey, titleKey } = getTextKeys(config);++ return (+ <div className = 'welcome-card welcome-card--notification'>+ { titleKey && <h3 className = 'welcome-notification-title'>{ t(titleKey) }</h3> }+ { descriptionKey && <p className = 'welcome-notification-description'>{ t(descriptionKey) }</p> }+ <a+ className = 'welcome-notification-link'+ href = { config.url }+ rel = 'noopener noreferrer'+ target = '_blank'>+ { t(buttonKey) }+ </a>+ </div>+ );+};++export default WelcomePageNotification;diff --git a/react/features/system-wide-user-notification/constants.ts b/react/features/system-wide-user-notification/constants.tsnew file mode 100644index 0000000000..fd5dc1f270--- /dev/null+++ b/react/features/system-wide-user-notification/constants.ts@@ -0,0 +1,19 @@+/**+ * The local storage key which holds the id of the last system-wide user notification the user chose not to see again.+ */+export const SYSTEM_WIDE_USER_NOTIFICATION_HIDDEN = 'systemWideUserNotificationHidden';++/**+ * The identifier of the system-wide user notification.+ */+export const SYSTEM_WIDE_USER_NOTIFICATION_ID = 'SYSTEM_WIDE_USER_NOTIFICATION';++/**+ * The translation keys of the texts. The labels from the config are added to the language bundles under these keys.+ */+export const SYSTEM_WIDE_USER_NOTIFICATION_KEYS = {+ button: 'systemWideUserNotification.button',+ description: 'systemWideUserNotification.description',+ dontShowAgain: 'systemWideUserNotification.dontShowAgain',+ title: 'systemWideUserNotification.title'+};diff --git a/react/features/system-wide-user-notification/functions.ts b/react/features/system-wide-user-notification/functions.tsnew file mode 100644index 0000000000..50b730b137--- /dev/null+++ b/react/features/system-wide-user-notification/functions.ts@@ -0,0 +1,86 @@+import { jitsiLocalStorage } from '@jitsi/js-utils';++import { IReduxState } from '../app/types';+import i18next from '../base/i18n/i18next';++import { SYSTEM_WIDE_USER_NOTIFICATION_HIDDEN, SYSTEM_WIDE_USER_NOTIFICATION_KEYS } from './constants';+import { ISystemWideUserNotificationConfig } from './types';++/**+ * Returns the config of the system-wide user notification, if the notification is enabled.+ *+ * @param {IReduxState} state - The redux state.+ * @returns {ISystemWideUserNotificationConfig|undefined}+ */+export function getSystemWideUserNotification(state: IReduxState): ISystemWideUserNotificationConfig | undefined {+ const config = state['features/base/config'].systemWideUserNotification;++ if (config?.url && config.labels) {+ return config;+ }+}++/**+ * Returns the id of the system-wide user notification.+ *+ * @param {ISystemWideUserNotificationConfig} config - The config of the notification.+ * @returns {string}+ */+function getId(config: ISystemWideUserNotificationConfig) {+ return config.id ?? config.url ?? '';+}++/**+ * Returns the translation keys of the texts which the config has in at least one language. The button labels always+ * have a default text.+ *+ * @param {ISystemWideUserNotificationConfig} config - The config of the notification.+ * @returns {Object}+ */+export function getTextKeys(config: ISystemWideUserNotificationConfig) {+ const labels = Object.values(config.labels ?? {});++ return {+ buttonKey: SYSTEM_WIDE_USER_NOTIFICATION_KEYS.button,+ descriptionKey: labels.some(l => l?.description) ? SYSTEM_WIDE_USER_NOTIFICATION_KEYS.description : undefined,+ dontShowAgainKey: SYSTEM_WIDE_USER_NOTIFICATION_KEYS.dontShowAgain,+ titleKey: labels.some(l => l?.title) ? SYSTEM_WIDE_USER_NOTIFICATION_KEYS.title : undefined+ };+}++/**+ * Adds the labels from the config to the language bundles, the way dynamic branding adds its labels.+ *+ * @param {ISystemWideUserNotificationConfig} config - The config of the notification.+ * @returns {void}+ */+export function addLabelsToLanguageBundles(config: ISystemWideUserNotificationConfig) {+ Object.entries(config.labels ?? {}).forEach(([ language, labels ]) => {+ i18next.addResourceBundle(+ language,+ 'main',+ { systemWideUserNotification: labels },+ /* deep */ true,+ /* overwrite */ true);+ });+}++/**+ * Whether the user chose not to see this notification again.+ *+ * @param {ISystemWideUserNotificationConfig} config - The config of the notification.+ * @returns {boolean}+ */+export function isHidden(config: ISystemWideUserNotificationConfig) {+ return jitsiLocalStorage.getItem(SYSTEM_WIDE_USER_NOTIFICATION_HIDDEN) === getId(config);+}++/**+ * Remembers that the user chose not to see this notification again.+ *+ * @param {ISystemWideUserNotificationConfig} config - The config of the notification.+ * @returns {void}+ */+export function hide(config: ISystemWideUserNotificationConfig) {+ jitsiLocalStorage.setItem(SYSTEM_WIDE_USER_NOTIFICATION_HIDDEN, getId(config));+}diff --git a/react/features/system-wide-user-notification/middleware.ts b/react/features/system-wide-user-notification/middleware.tsnew file mode 100644index 0000000000..3ae5dbc521--- /dev/null+++ b/react/features/system-wide-user-notification/middleware.ts@@ -0,0 +1,76 @@+import { CONFERENCE_JOINED } from '../base/conference/actionTypes';+import { SET_CONFIG } from '../base/config/actionTypes';+import { I18NEXT_INITIALIZED, LANGUAGE_CHANGED } from '../base/i18n/actionTypes';+import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';+import { BUTTON_TYPES } from '../base/ui/constants.any';+import { openURLInBrowser } from '../base/util/openURLInBrowser';+import { showNotification } from '../notifications/actions';+import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';++import { SYSTEM_WIDE_USER_NOTIFICATION_ID } from './constants';+import {+ addLabelsToLanguageBundles,+ getSystemWideUserNotification,+ getTextKeys,+ hide,+ isHidden+} from './functions';++/**+ * Middleware that shows the system-wide user notification when the user joins a conference, until the user chooses+ * not to see it again.+ *+ * @param {IStore} store - The redux store.+ * @returns {Function}+ */+MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {+ const result = next(action);++ switch (action.type) {+ case I18NEXT_INITIALIZED:+ case LANGUAGE_CHANGED:+ case SET_CONFIG: {+ // A language bundle which loads later replaces the labels, so they are added again when the language+ // changes.+ const config = getSystemWideUserNotification(getState());++ config && addLabelsToLanguageBundles(config);++ break;+ }+ case CONFERENCE_JOINED: {+ const config = getSystemWideUserNotification(getState());++ if (!config?.url || isHidden(config)) {+ break;+ }++ const { url } = config;+ const { buttonKey, descriptionKey, dontShowAgainKey, titleKey } = getTextKeys(config);++ dispatch(showNotification({+ customActionHandler: [+ () => {+ openURLInBrowser(url, true);++ return true;+ },+ () => {+ hide(config);++ return true;+ }+ ],+ customActionNameKey: [ buttonKey, dontShowAgainKey ],+ customActionType: [ BUTTON_TYPES.PRIMARY, BUTTON_TYPES.TERTIARY ],+ descriptionKey,+ titleKey,+ uid: SYSTEM_WIDE_USER_NOTIFICATION_ID+ }, NOTIFICATION_TIMEOUT_TYPE.STICKY));++ break;+ }+ }++ return result;+});diff --git a/react/features/system-wide-user-notification/types.ts b/react/features/system-wide-user-notification/types.tsnew file mode 100644index 0000000000..ed2991a48b--- /dev/null+++ b/react/features/system-wide-user-notification/types.ts@@ -0,0 +1,47 @@+/**+ * The texts of the system-wide user notification in one language.+ */+export interface ISystemWideUserNotificationLabels {++ /**+ * The label of the button which opens the link.+ */+ button?: string;++ /**+ * The description.+ */+ description?: string;++ /**+ * The label of the button which hides the notification for good.+ */+ dontShowAgain?: string;++ /**+ * The title.+ */+ title?: string;+}++/**+ * The config of the system-wide user notification.+ */+export interface ISystemWideUserNotificationConfig {++ /**+ * Identifies the notification. The users who chose not to see a notification again see the notification again+ * when its id changes. Defaults to the url.+ */+ id?: string;++ /**+ * The texts, by language code. A missing language or text falls back to English.+ */+ labels?: Record<string, ISystemWideUserNotificationLabels>;++ /**+ * The link which is opened in the browser.+ */+ url?: string;+}diff --git a/react/features/welcome/components/WelcomePage.web.tsx b/react/features/welcome/components/WelcomePage.web.tsxindex 774437cd9a..e9209961c3 100644--- a/react/features/welcome/components/WelcomePage.web.tsx+++ b/react/features/welcome/components/WelcomePage.web.tsx@@ -11,6 +11,7 @@ import CalendarList from '../../calendar-sync/components/CalendarList.web';import RecentList from '../../recent-list/components/RecentList.web';import SettingsButton from '../../settings/components/web/SettingsButton';import { SETTINGS_TABS } from '../../settings/constants';+import WelcomePageNotification from '../../system-wide-user-notification/components/web/WelcomePageNotification';import { AbstractWelcomePage, IProps, _mapStateToProps } from './AbstractWelcomePage';import Tabs from './Tabs';@@ -282,6 +283,7 @@ class WelcomePage extends AbstractWelcomePage<IProps> {<div className = 'welcome-cards-container'><div className = 'welcome-card-column'>+ <WelcomePageNotification /><div className = 'welcome-tabs welcome-card welcome-card--blue'>{this._renderTabs()}</div>