2018-06-14 09:14:32 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
import throttle from 'lodash/throttle';
|
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
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';
|
2019-06-25 22:25:43 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT, NOTIFICATION_TYPE } from './constants';
|
2017-07-28 17:56:49 +00:00
|
|
|
|
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,
|
2017-07-31 18:36:41 +00:00
|
|
|
* uid: number
|
2017-07-28 17:56:49 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
export function hideNotification(uid: number) {
|
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.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
export function showErrorNotification(props: Object) {
|
2017-12-11 18:33:09 +00:00
|
|
|
return showNotification({
|
2017-11-03 19:05:03 +00:00
|
|
|
...props,
|
|
|
|
appearance: NOTIFICATION_TYPE.ERROR
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Queues a notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
|
|
|
* @param {number} timeout - How long the notification should display before
|
|
|
|
* automatically being hidden.
|
|
|
|
* @returns {{
|
|
|
|
* type: SHOW_NOTIFICATION,
|
|
|
|
* props: Object,
|
|
|
|
* timeout: number,
|
|
|
|
* uid: number
|
|
|
|
* }}
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
export function showNotification(props: Object = {}, timeout: ?number) {
|
2017-07-28 17:56:49 +00:00
|
|
|
return {
|
|
|
|
type: SHOW_NOTIFICATION,
|
|
|
|
props,
|
|
|
|
timeout,
|
|
|
|
uid: window.Date.now()
|
|
|
|
};
|
|
|
|
}
|
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.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
export function showWarningNotification(props: Object) {
|
2017-12-11 18:33:09 +00:00
|
|
|
return showNotification({
|
2017-11-03 19:05:03 +00:00
|
|
|
...props,
|
|
|
|
appearance: NOTIFICATION_TYPE.WARNING
|
|
|
|
});
|
|
|
|
}
|
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[]}
|
|
|
|
*/
|
|
|
|
let joinedParticipantsNames = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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}
|
|
|
|
*/
|
|
|
|
const _throttledNotifyParticipantConnected = throttle((dispatch: Dispatch<any>) => {
|
|
|
|
const joinedParticipantsCount = joinedParticipantsNames.length;
|
|
|
|
|
|
|
|
let notificationProps;
|
|
|
|
|
|
|
|
if (joinedParticipantsCount >= 3) {
|
|
|
|
notificationProps = {
|
|
|
|
titleArguments: {
|
|
|
|
name: joinedParticipantsNames[0],
|
|
|
|
count: joinedParticipantsCount - 1
|
|
|
|
},
|
|
|
|
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(
|
|
|
|
showNotification(notificationProps, NOTIFICATION_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
joinedParticipantsNames = [];
|
|
|
|
|
|
|
|
}, 500, { leading: false });
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
joinedParticipantsNames.push(displayName);
|
|
|
|
|
|
|
|
return (dispatch: Dispatch<any>) => _throttledNotifyParticipantConnected(dispatch);
|
|
|
|
}
|