feat(notifications) skip join notifications when meetings grow large

This commit is contained in:
Saúl Ibarra Corretgé 2021-09-02 14:47:11 +02:00 committed by Saúl Ibarra Corretgé
parent c730676ce6
commit 9a8b67a0a4
2 changed files with 22 additions and 3 deletions

View File

@ -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<any>) => {
const _throttledNotifyParticipantConnected = throttle((dispatch: Dispatch<any>, 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<any>)
export function showParticipantJoinedNotification(displayName: string) {
joinedParticipantsNames.push(displayName);
return (dispatch: Dispatch<any>) => _throttledNotifyParticipantConnected(dispatch);
return (dispatch: Dispatch<any>, getState: Function) => _throttledNotifyParticipantConnected(dispatch, getState);
}

View File

@ -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;