From ac02a17943bf0877f682c9d5f57b39a95ebae9c5 Mon Sep 17 00:00:00 2001 From: virtuacoplenny Date: Thu, 21 Mar 2019 14:06:33 -0700 Subject: [PATCH] feat(notifications): provide a way to turn off sticky notifications (#4010) --- interface_config.js | 9 +++++- .../AbstractNotificationsContainer.js | 29 ++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/interface_config.js b/interface_config.js index d8222658b9..1778753215 100644 --- a/interface_config.js +++ b/interface_config.js @@ -193,7 +193,14 @@ var interfaceConfig = { /** * Specify the Android app package name. */ - // ANDROID_APP_PACKAGE: 'org.jitsi.meet' + // ANDROID_APP_PACKAGE: 'org.jitsi.meet', + + /** + * Override the behavior of some notifications to remain displayed until + * explicitly dismissed through a user action. The value is how long, in + * milliseconds, those notifications should remain displayed. + */ + // ENFORCE_NOTIFICATION_AUTO_DISMISS_TIMEOUT: 15000, }; /* eslint-enable no-unused-vars, no-var, max-len */ diff --git a/react/features/notifications/components/AbstractNotificationsContainer.js b/react/features/notifications/components/AbstractNotificationsContainer.js index 7777f0c4dc..c72b027987 100644 --- a/react/features/notifications/components/AbstractNotificationsContainer.js +++ b/react/features/notifications/components/AbstractNotificationsContainer.js @@ -13,12 +13,20 @@ export type Props = { */ _notifications: Array, + /** + * The length, in milliseconds, to use as a default timeout for all + * dismissable timeouts that do not have a timeout specified. + */ + autoDismissTimeout: number, + /** * Invoked to update the redux store in order to remove notifications. */ dispatch: Function }; +declare var interfaceConfig: Object; + /** * Abstract class for {@code NotificationsContainer} component. */ @@ -78,7 +86,7 @@ export default class AbstractNotificationsContainer * @private */ _manageDismissTimeout(prevProps: ?P) { - const { _notifications } = this.props; + const { _notifications, autoDismissTimeout } = this.props; if (_notifications.length) { const notification = _notifications[0]; @@ -90,14 +98,18 @@ export default class AbstractNotificationsContainer if (notification !== previousNotification) { this._clearNotificationDismissTimeout(); - if (notification) { - const { timeout, uid } = notification; + if (notification + && (notification.timeout + || typeof autoDismissTimeout === 'number') + && notification.props.isDismissAllowed !== false) { + const { + timeout = autoDismissTimeout, + uid + } = notification; this._notificationDismissTimeout = setTimeout(() => { // Perform a no-op if a timeout is not specified. - if (Number.isInteger(timeout)) { - this._onDismissed(uid); - } + this._onDismissed(uid); }, timeout); } } @@ -168,6 +180,9 @@ export function _abstractMapStateToProps(state: Object) { const _visible = areThereNotifications(state); return { - _notifications: _visible ? notifications : [] + _notifications: _visible ? notifications : [], + autoDismissTimeout: typeof interfaceConfig === 'undefined' + ? undefined // Ignore for the case of mobile + : interfaceConfig.ENFORCE_NOTIFICATION_AUTO_DISMISS_TIMEOUT }; }