From 9a8b67a0a46ac2025123c8cf5ce98fae77ecf1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 2 Sep 2021 14:47:11 +0200 Subject: [PATCH] feat(notifications) skip join notifications when meetings grow large --- react/features/notifications/actions.js | 20 +++++++++++++++++--- react/features/notifications/constants.js | 5 +++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/react/features/notifications/actions.js b/react/features/notifications/actions.js index cc40768c3..a202e0379 100644 --- a/react/features/notifications/actions.js +++ b/react/features/notifications/actions.js @@ -4,6 +4,7 @@ import throttle from 'lodash/throttle'; import type { Dispatch } from 'redux'; import { NOTIFICATIONS_ENABLED, getFeatureFlag } from '../base/flags'; +import { getParticipantCount } from '../base/participants/functions'; import { CLEAR_NOTIFICATIONS, @@ -11,7 +12,11 @@ import { SET_NOTIFICATIONS_ENABLED, SHOW_NOTIFICATION } from './actionTypes'; -import { NOTIFICATION_TIMEOUT, NOTIFICATION_TYPE } from './constants'; +import { + NOTIFICATION_TIMEOUT, + NOTIFICATION_TYPE, + SILENT_JOIN_THRESHOLD +} from './constants'; /** * Clears (removes) all the notifications. @@ -133,7 +138,16 @@ let joinedParticipantsNames = []; * @private * @type {Function} */ -const _throttledNotifyParticipantConnected = throttle((dispatch: Dispatch) => { +const _throttledNotifyParticipantConnected = throttle((dispatch: Dispatch, getState: Function) => { + const participantCount = getParticipantCount(getState()); + + // Skip join notifications altogether for large meetings. + if (participantCount > SILENT_JOIN_THRESHOLD) { + joinedParticipantsNames = []; + + return; + } + const joinedParticipantsCount = joinedParticipantsNames.length; let notificationProps; @@ -182,5 +196,5 @@ const _throttledNotifyParticipantConnected = throttle((dispatch: Dispatch) export function showParticipantJoinedNotification(displayName: string) { joinedParticipantsNames.push(displayName); - return (dispatch: Dispatch) => _throttledNotifyParticipantConnected(dispatch); + return (dispatch: Dispatch, getState: Function) => _throttledNotifyParticipantConnected(dispatch, getState); } diff --git a/react/features/notifications/constants.js b/react/features/notifications/constants.js index 643871a6b..73213206d 100644 --- a/react/features/notifications/constants.js +++ b/react/features/notifications/constants.js @@ -30,3 +30,8 @@ export const NOTIFICATION_TYPE_PRIORITIES = { [NOTIFICATION_TYPE.SUCCESS]: 3, [NOTIFICATION_TYPE.WARNING]: 4 }; + +/** + * Amount of participants beyond which no join notification will be emitted. + */ +export const SILENT_JOIN_THRESHOLD = 30;