2019-06-25 22:25:43 +00:00
|
|
|
import throttle from 'lodash/throttle';
|
|
|
|
|
2022-09-21 08:32:50 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { NOTIFICATIONS_ENABLED } from '../base/flags/constants';
|
|
|
|
import { getFeatureFlag } from '../base/flags/functions';
|
2021-09-02 12:47:11 +00:00
|
|
|
import { getParticipantCount } from '../base/participants/functions';
|
2021-01-22 10:03:39 +00:00
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
import {
|
2018-06-14 09:14:32 +00:00
|
|
|
CLEAR_NOTIFICATIONS,
|
2017-07-28 17:56:49 +00:00
|
|
|
HIDE_NOTIFICATION,
|
2017-08-02 18:15:55 +00:00
|
|
|
SET_NOTIFICATIONS_ENABLED,
|
2017-07-28 17:56:49 +00:00
|
|
|
SHOW_NOTIFICATION
|
|
|
|
} from './actionTypes';
|
2021-09-02 12:47:11 +00:00
|
|
|
import {
|
2021-12-17 12:39:15 +00:00
|
|
|
NOTIFICATION_ICON,
|
2021-09-02 12:47:11 +00:00
|
|
|
NOTIFICATION_TIMEOUT,
|
2022-09-27 07:10:28 +00:00
|
|
|
NOTIFICATION_TIMEOUT_TYPE,
|
2021-09-02 12:47:11 +00:00
|
|
|
NOTIFICATION_TYPE,
|
2021-12-02 13:17:07 +00:00
|
|
|
SILENT_JOIN_THRESHOLD,
|
|
|
|
SILENT_LEFT_THRESHOLD
|
2021-09-02 12:47:11 +00:00
|
|
|
} from './constants';
|
2022-10-13 08:26:28 +00:00
|
|
|
import { INotificationProps } from './types';
|
2017-07-28 17:56:49 +00:00
|
|
|
|
2021-11-24 11:05:27 +00:00
|
|
|
/**
|
|
|
|
* Function that returns notification timeout value based on notification timeout type.
|
|
|
|
*
|
|
|
|
* @param {string} type - Notification type.
|
|
|
|
* @param {Object} notificationTimeouts - Config notification timeouts.
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
function getNotificationTimeout(type?: string, notificationTimeouts?: {
|
|
|
|
long?: number;
|
|
|
|
medium?: number;
|
|
|
|
short?: number;
|
|
|
|
}) {
|
2021-11-24 11:05:27 +00:00
|
|
|
if (type === NOTIFICATION_TIMEOUT_TYPE.SHORT) {
|
|
|
|
return notificationTimeouts?.short ?? NOTIFICATION_TIMEOUT.SHORT;
|
|
|
|
} else if (type === NOTIFICATION_TIMEOUT_TYPE.MEDIUM) {
|
|
|
|
return notificationTimeouts?.medium ?? NOTIFICATION_TIMEOUT.MEDIUM;
|
|
|
|
} else if (type === NOTIFICATION_TIMEOUT_TYPE.LONG) {
|
|
|
|
return notificationTimeouts?.long ?? NOTIFICATION_TIMEOUT.LONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFICATION_TIMEOUT.STICKY;
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
/**
|
|
|
|
* Clears (removes) all the notifications.
|
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: CLEAR_NOTIFICATIONS
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function clearNotifications() {
|
|
|
|
return {
|
|
|
|
type: CLEAR_NOTIFICATIONS
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Removes the notification with the passed in id.
|
|
|
|
*
|
|
|
|
* @param {string} uid - The unique identifier for the notification to be
|
|
|
|
* removed.
|
|
|
|
* @returns {{
|
|
|
|
* type: HIDE_NOTIFICATION,
|
2021-06-23 11:23:44 +00:00
|
|
|
* uid: string
|
2017-07-28 17:56:49 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export function hideNotification(uid: string) {
|
2017-07-28 17:56:49 +00:00
|
|
|
return {
|
|
|
|
type: HIDE_NOTIFICATION,
|
|
|
|
uid
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:15:55 +00:00
|
|
|
/**
|
|
|
|
* Stops notifications from being displayed.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - Whether or not notifications should display.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_NOTIFICATIONS_ENABLED,
|
|
|
|
* enabled: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
export function setNotificationsEnabled(enabled: boolean) {
|
2017-08-02 18:15:55 +00:00
|
|
|
return {
|
|
|
|
type: SET_NOTIFICATIONS_ENABLED,
|
|
|
|
enabled
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
/**
|
|
|
|
* Queues an error notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
2021-11-24 11:05:27 +00:00
|
|
|
* @param {string} type - Notification type.
|
2017-11-03 19:05:03 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
export function showErrorNotification(props: INotificationProps, type?: string) {
|
2017-12-11 18:33:09 +00:00
|
|
|
return showNotification({
|
2017-11-03 19:05:03 +00:00
|
|
|
...props,
|
|
|
|
appearance: NOTIFICATION_TYPE.ERROR
|
2021-11-24 11:05:27 +00:00
|
|
|
}, type);
|
2017-11-03 19:05:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Queues a notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
2022-08-01 10:37:41 +00:00
|
|
|
* @param {string} type - Timeout type.
|
2021-01-11 10:52:52 +00:00
|
|
|
* @returns {Function}
|
2017-07-28 17:56:49 +00:00
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
export function showNotification(props: INotificationProps = {}, type?: string) {
|
|
|
|
return function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
|
2022-05-16 09:27:31 +00:00
|
|
|
const { disabledNotifications = [], notifications, notificationTimeouts } = getState()['features/base/config'];
|
2021-01-22 10:03:39 +00:00
|
|
|
const enabledFlag = getFeatureFlag(getState(), NOTIFICATIONS_ENABLED, true);
|
|
|
|
|
2023-02-27 13:31:54 +00:00
|
|
|
const { descriptionKey, titleKey } = props;
|
|
|
|
|
2021-01-22 10:03:39 +00:00
|
|
|
const shouldDisplay = enabledFlag
|
2023-02-27 13:31:54 +00:00
|
|
|
&& !(disabledNotifications.includes(descriptionKey ?? '')
|
|
|
|
|| disabledNotifications.includes(titleKey ?? ''))
|
2021-01-22 10:03:39 +00:00
|
|
|
&& (!notifications
|
2023-02-27 13:31:54 +00:00
|
|
|
|| notifications.includes(descriptionKey ?? '')
|
|
|
|
|| notifications.includes(titleKey ?? ''));
|
|
|
|
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyNotificationTriggered(titleKey, descriptionKey);
|
|
|
|
}
|
2021-01-11 10:52:52 +00:00
|
|
|
|
|
|
|
if (shouldDisplay) {
|
|
|
|
return dispatch({
|
|
|
|
type: SHOW_NOTIFICATION,
|
|
|
|
props,
|
2021-11-24 11:05:27 +00:00
|
|
|
timeout: getNotificationTimeout(type, notificationTimeouts),
|
2022-10-28 10:07:58 +00:00
|
|
|
uid: props.uid || Date.now().toString()
|
2021-01-11 10:52:52 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-28 17:56:49 +00:00
|
|
|
};
|
|
|
|
}
|
2017-07-31 18:36:41 +00:00
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
/**
|
|
|
|
* Queues a warning notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
2021-11-24 11:05:27 +00:00
|
|
|
* @param {string} type - Notification type.
|
2017-11-03 19:05:03 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
export function showWarningNotification(props: INotificationProps, type?: string) {
|
2021-11-24 11:05:27 +00:00
|
|
|
|
2017-12-11 18:33:09 +00:00
|
|
|
return showNotification({
|
2017-11-03 19:05:03 +00:00
|
|
|
...props,
|
|
|
|
appearance: NOTIFICATION_TYPE.WARNING
|
2021-11-24 11:05:27 +00:00
|
|
|
}, type);
|
2017-11-03 19:05:03 +00:00
|
|
|
}
|
2019-06-25 22:25:43 +00:00
|
|
|
|
2021-12-17 12:39:15 +00:00
|
|
|
/**
|
|
|
|
* Queues a message notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
|
|
|
* @param {string} type - Notification type.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
export function showMessageNotification(props: INotificationProps, type?: string) {
|
2021-12-17 12:39:15 +00:00
|
|
|
return showNotification({
|
|
|
|
...props,
|
|
|
|
concatText: true,
|
|
|
|
titleKey: 'notify.chatMessages',
|
|
|
|
appearance: NOTIFICATION_TYPE.NORMAL,
|
|
|
|
icon: NOTIFICATION_ICON.MESSAGE
|
|
|
|
}, type);
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
/**
|
|
|
|
* An array of names of participants that have joined the conference. The array
|
|
|
|
* is replaced with an empty array as notifications are displayed.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {string[]}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
let joinedParticipantsNames: string[] = [];
|
2019-06-25 22:25:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A throttled internal function that takes the internal list of participant
|
|
|
|
* names, {@code joinedParticipantsNames}, and triggers the display of a
|
|
|
|
* notification informing of their joining.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
const _throttledNotifyParticipantConnected = throttle((dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2021-09-02 12:47:11 +00:00
|
|
|
const participantCount = getParticipantCount(getState());
|
|
|
|
|
|
|
|
// Skip join notifications altogether for large meetings.
|
|
|
|
if (participantCount > SILENT_JOIN_THRESHOLD) {
|
|
|
|
joinedParticipantsNames = [];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
const joinedParticipantsCount = joinedParticipantsNames.length;
|
|
|
|
|
|
|
|
let notificationProps;
|
|
|
|
|
|
|
|
if (joinedParticipantsCount >= 3) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
2021-09-02 12:46:16 +00:00
|
|
|
name: joinedParticipantsNames[0]
|
2019-06-25 22:25:43 +00:00
|
|
|
},
|
|
|
|
titleKey: 'notify.connectedThreePlusMembers'
|
|
|
|
};
|
|
|
|
} else if (joinedParticipantsCount === 2) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
|
|
|
first: joinedParticipantsNames[0],
|
|
|
|
second: joinedParticipantsNames[1]
|
|
|
|
},
|
|
|
|
titleKey: 'notify.connectedTwoMembers'
|
|
|
|
};
|
|
|
|
} else if (joinedParticipantsCount) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
|
|
|
name: joinedParticipantsNames[0]
|
|
|
|
},
|
|
|
|
titleKey: 'notify.connectedOneMember'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notificationProps) {
|
|
|
|
dispatch(
|
2021-11-24 11:05:27 +00:00
|
|
|
showNotification(notificationProps, NOTIFICATION_TIMEOUT_TYPE.SHORT));
|
2019-06-25 22:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
joinedParticipantsNames = [];
|
|
|
|
|
2021-09-02 12:45:27 +00:00
|
|
|
}, 2000, { leading: false });
|
2019-06-25 22:25:43 +00:00
|
|
|
|
2021-12-02 13:17:07 +00:00
|
|
|
/**
|
|
|
|
* An array of names of participants that have left the conference. The array
|
|
|
|
* is replaced with an empty array as notifications are displayed.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {string[]}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
let leftParticipantsNames: string[] = [];
|
2021-12-02 13:17:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A throttled internal function that takes the internal list of participant
|
|
|
|
* names, {@code leftParticipantsNames}, and triggers the display of a
|
|
|
|
* notification informing of their leaving.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
const _throttledNotifyParticipantLeft = throttle((dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2021-12-02 13:17:07 +00:00
|
|
|
const participantCount = getParticipantCount(getState());
|
|
|
|
|
|
|
|
// Skip left notifications altogether for large meetings.
|
|
|
|
if (participantCount > SILENT_LEFT_THRESHOLD) {
|
|
|
|
leftParticipantsNames = [];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const leftParticipantsCount = leftParticipantsNames.length;
|
|
|
|
|
|
|
|
let notificationProps;
|
|
|
|
|
|
|
|
if (leftParticipantsCount >= 3) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
|
|
|
name: leftParticipantsNames[0]
|
|
|
|
},
|
|
|
|
titleKey: 'notify.leftThreePlusMembers'
|
|
|
|
};
|
|
|
|
} else if (leftParticipantsCount === 2) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
|
|
|
first: leftParticipantsNames[0],
|
|
|
|
second: leftParticipantsNames[1]
|
|
|
|
},
|
|
|
|
titleKey: 'notify.leftTwoMembers'
|
|
|
|
};
|
|
|
|
} else if (leftParticipantsCount) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
|
|
|
name: leftParticipantsNames[0]
|
|
|
|
},
|
|
|
|
titleKey: 'notify.leftOneMember'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notificationProps) {
|
|
|
|
dispatch(
|
|
|
|
showNotification(notificationProps, NOTIFICATION_TIMEOUT_TYPE.SHORT));
|
|
|
|
}
|
|
|
|
|
|
|
|
leftParticipantsNames = [];
|
|
|
|
|
|
|
|
}, 2000, { leading: false });
|
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
/**
|
|
|
|
* Queues the display of a notification of a participant having connected to
|
|
|
|
* the meeting. The notifications are batched so that quick consecutive
|
|
|
|
* connection events are shown in one notification.
|
|
|
|
*
|
|
|
|
* @param {string} displayName - The name of the participant that connected.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function showParticipantJoinedNotification(displayName: string) {
|
2021-12-15 19:22:09 +00:00
|
|
|
joinedParticipantsNames.push(displayName);
|
2019-06-25 22:25:43 +00:00
|
|
|
|
2022-09-21 08:32:50 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) =>
|
|
|
|
_throttledNotifyParticipantConnected(dispatch, getState);
|
2019-06-25 22:25:43 +00:00
|
|
|
}
|
2021-12-02 13:17:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Queues the display of a notification of a participant having left to
|
|
|
|
* the meeting. The notifications are batched so that quick consecutive
|
|
|
|
* connection events are shown in one notification.
|
|
|
|
*
|
|
|
|
* @param {string} displayName - The name of the participant that left.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function showParticipantLeftNotification(displayName: string) {
|
2021-12-15 19:22:09 +00:00
|
|
|
leftParticipantsNames.push(displayName);
|
2021-12-02 13:17:07 +00:00
|
|
|
|
2022-09-21 08:32:50 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) =>
|
|
|
|
_throttledNotifyParticipantLeft(dispatch, getState);
|
2021-12-02 13:17:07 +00:00
|
|
|
}
|