2018-06-14 09:14:32 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import { getCurrentConference } from '../base/conference';
|
2019-06-25 22:25:43 +00:00
|
|
|
import {
|
|
|
|
PARTICIPANT_JOINED,
|
2019-06-26 20:14:32 +00:00
|
|
|
PARTICIPANT_LEFT,
|
2020-02-18 16:31:04 +00:00
|
|
|
PARTICIPANT_ROLE,
|
|
|
|
PARTICIPANT_UPDATED,
|
2019-06-26 20:14:32 +00:00
|
|
|
getParticipantById,
|
2021-09-10 11:05:16 +00:00
|
|
|
getParticipantDisplayName,
|
|
|
|
getLocalParticipant
|
2019-06-25 22:25:43 +00:00
|
|
|
} from '../base/participants';
|
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
2021-09-10 11:05:16 +00:00
|
|
|
import { PARTICIPANTS_PANE_OPEN } from '../participants-pane/actionTypes';
|
2018-06-14 09:14:32 +00:00
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
import {
|
|
|
|
clearNotifications,
|
2021-09-10 11:05:16 +00:00
|
|
|
hideRaiseHandNotifications,
|
2019-06-26 20:14:32 +00:00
|
|
|
showNotification,
|
2019-06-25 22:25:43 +00:00
|
|
|
showParticipantJoinedNotification
|
|
|
|
} from './actions';
|
2019-06-26 20:14:32 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT } from './constants';
|
2020-01-14 09:41:16 +00:00
|
|
|
import { joinLeaveNotificationsDisabled } from './functions';
|
2019-06-26 20:14:32 +00:00
|
|
|
|
|
|
|
declare var interfaceConfig: Object;
|
2019-06-25 22:25:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that captures actions to display notifications.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case PARTICIPANT_JOINED: {
|
2019-06-26 20:14:32 +00:00
|
|
|
const result = next(action);
|
2019-06-25 22:25:43 +00:00
|
|
|
const { participant: p } = action;
|
2020-02-18 16:31:04 +00:00
|
|
|
const { dispatch, getState } = store;
|
2021-09-01 15:54:07 +00:00
|
|
|
const state = getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
2019-06-25 22:25:43 +00:00
|
|
|
|
2021-09-01 15:54:07 +00:00
|
|
|
if (conference && !p.local && !joinLeaveNotificationsDisabled() && !p.isReplacing) {
|
2020-02-18 16:31:04 +00:00
|
|
|
dispatch(showParticipantJoinedNotification(
|
2021-09-01 15:54:07 +00:00
|
|
|
getParticipantDisplayName(state, p.id)
|
2019-06-25 22:25:43 +00:00
|
|
|
));
|
|
|
|
}
|
2019-06-26 20:14:32 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_LEFT: {
|
2020-01-14 09:41:16 +00:00
|
|
|
if (!joinLeaveNotificationsDisabled()) {
|
|
|
|
const participant = getParticipantById(
|
|
|
|
store.getState(),
|
|
|
|
action.participant.id
|
|
|
|
);
|
2019-06-26 20:14:32 +00:00
|
|
|
|
2020-01-14 09:41:16 +00:00
|
|
|
if (typeof interfaceConfig === 'object'
|
|
|
|
&& participant
|
2021-06-11 08:58:45 +00:00
|
|
|
&& !participant.local
|
|
|
|
&& !action.participant.isReplaced) {
|
2020-01-14 09:41:16 +00:00
|
|
|
store.dispatch(showNotification({
|
|
|
|
descriptionKey: 'notify.disconnected',
|
|
|
|
titleKey: 'notify.somebody',
|
|
|
|
title: participant.name
|
|
|
|
}, NOTIFICATION_TIMEOUT));
|
|
|
|
}
|
2019-06-26 20:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
2019-06-25 22:25:43 +00:00
|
|
|
}
|
2020-02-18 16:31:04 +00:00
|
|
|
case PARTICIPANT_UPDATED: {
|
2021-09-21 15:38:06 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const { disableModeratorIndicator } = state['features/base/config'];
|
|
|
|
|
|
|
|
if (disableModeratorIndicator) {
|
2020-02-18 16:31:04 +00:00
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { id, role } = action.participant;
|
2021-09-10 11:05:16 +00:00
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
if (localParticipant.id !== id) {
|
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:40:36 +00:00
|
|
|
const oldParticipant = getParticipantById(state, id);
|
|
|
|
const oldRole = oldParticipant?.role;
|
2020-02-18 16:31:04 +00:00
|
|
|
|
2020-03-19 17:40:36 +00:00
|
|
|
if (oldRole && oldRole !== role && role === PARTICIPANT_ROLE.MODERATOR) {
|
2020-02-18 16:31:04 +00:00
|
|
|
|
|
|
|
store.dispatch(showNotification({
|
2021-09-10 11:05:16 +00:00
|
|
|
titleKey: 'notify.moderator'
|
2020-02-18 16:31:04 +00:00
|
|
|
},
|
|
|
|
NOTIFICATION_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|
2021-09-10 11:05:16 +00:00
|
|
|
case PARTICIPANTS_PANE_OPEN: {
|
|
|
|
store.dispatch(hideRaiseHandNotifications());
|
|
|
|
break;
|
|
|
|
}
|
2019-06-25 22:25:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 20:14:32 +00:00
|
|
|
return next(action);
|
2019-06-25 22:25:43 +00:00
|
|
|
});
|
2018-06-14 09:14:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* StateListenerRegistry provides a reliable way to detect the leaving of a
|
|
|
|
* conference, where we need to clean up the notifications.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => getCurrentConference(state),
|
|
|
|
/* listener */ (conference, { dispatch }) => {
|
|
|
|
if (!conference) {
|
|
|
|
dispatch(clearNotifications());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|