|
|
|
@ -13,15 +13,65 @@ import { |
|
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux'; |
|
|
|
|
import { PARTICIPANTS_PANE_OPEN } from '../participants-pane/actionTypes'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
CLEAR_NOTIFICATIONS, |
|
|
|
|
HIDE_NOTIFICATION, |
|
|
|
|
SHOW_NOTIFICATION |
|
|
|
|
} from './actionTypes'; |
|
|
|
|
import { |
|
|
|
|
clearNotifications, |
|
|
|
|
hideRaiseHandNotifications, |
|
|
|
|
hideNotification, |
|
|
|
|
showNotification, |
|
|
|
|
showParticipantJoinedNotification, |
|
|
|
|
showParticipantLeftNotification |
|
|
|
|
} from './actions'; |
|
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from './constants'; |
|
|
|
|
import { joinLeaveNotificationsDisabled } from './functions'; |
|
|
|
|
import { |
|
|
|
|
NOTIFICATION_TIMEOUT_TYPE, |
|
|
|
|
RAISE_HAND_NOTIFICATION_ID |
|
|
|
|
} from './constants'; |
|
|
|
|
import { areThereNotifications, joinLeaveNotificationsDisabled } from './functions'; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Map of timers. |
|
|
|
|
* |
|
|
|
|
* @type {Map} |
|
|
|
|
*/ |
|
|
|
|
const timers = new Map(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Function that creates a timeout id for specific notification. |
|
|
|
|
* |
|
|
|
|
* @param {Object} notification - Notification for which we want to create a timeout. |
|
|
|
|
* @param {Function} dispatch - The Redux dispatch function. |
|
|
|
|
* @returns {void} |
|
|
|
|
*/ |
|
|
|
|
const createTimeoutId = (notification, dispatch) => { |
|
|
|
|
const { |
|
|
|
|
timeout, |
|
|
|
|
uid |
|
|
|
|
} = notification; |
|
|
|
|
|
|
|
|
|
if (timeout) { |
|
|
|
|
const timerID = setTimeout(() => { |
|
|
|
|
dispatch(hideNotification(uid)); |
|
|
|
|
}, timeout); |
|
|
|
|
|
|
|
|
|
timers.set(uid, timerID); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns notifications state. |
|
|
|
|
* |
|
|
|
|
* @param {Object} state - Global state. |
|
|
|
|
* @returns {Array<Object>} - Notifications state. |
|
|
|
|
*/ |
|
|
|
|
const getNotifications = state => { |
|
|
|
|
const _visible = areThereNotifications(state); |
|
|
|
|
const { notifications } = state['features/notifications']; |
|
|
|
|
|
|
|
|
|
return _visible ? notifications : []; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Middleware that captures actions to display notifications. |
|
|
|
@ -30,12 +80,52 @@ import { joinLeaveNotificationsDisabled } from './functions'; |
|
|
|
|
* @returns {Function} |
|
|
|
|
*/ |
|
|
|
|
MiddlewareRegistry.register(store => next => action => { |
|
|
|
|
|
|
|
|
|
const { dispatch, getState } = store; |
|
|
|
|
const state = getState(); |
|
|
|
|
|
|
|
|
|
switch (action.type) { |
|
|
|
|
case CLEAR_NOTIFICATIONS: { |
|
|
|
|
if (navigator.product !== 'ReactNative') { |
|
|
|
|
const _notifications = getNotifications(state); |
|
|
|
|
|
|
|
|
|
for (const notification of _notifications) { |
|
|
|
|
if (timers.has(notification.uid)) { |
|
|
|
|
const timeout = timers.get(notification.uid); |
|
|
|
|
|
|
|
|
|
clearTimeout(timeout); |
|
|
|
|
timers.delete(notification.uid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
timers.clear(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case SHOW_NOTIFICATION: { |
|
|
|
|
if (navigator.product !== 'ReactNative') { |
|
|
|
|
if (timers.has(action.uid)) { |
|
|
|
|
const timer = timers.get(action.uid); |
|
|
|
|
|
|
|
|
|
clearTimeout(timer); |
|
|
|
|
timers.delete(action.uid); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
createTimeoutId(action, dispatch); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case HIDE_NOTIFICATION: { |
|
|
|
|
if (navigator.product !== 'ReactNative') { |
|
|
|
|
const timer = timers.get(action.uid); |
|
|
|
|
|
|
|
|
|
clearTimeout(timer); |
|
|
|
|
timers.delete(action.uid); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case PARTICIPANT_JOINED: { |
|
|
|
|
const result = next(action); |
|
|
|
|
const { participant: p } = action; |
|
|
|
|
const { dispatch, getState } = store; |
|
|
|
|
const state = getState(); |
|
|
|
|
const { conference } = state['features/base/conference']; |
|
|
|
|
|
|
|
|
|
if (conference && !p.local && !joinLeaveNotificationsDisabled() && !p.isReplacing) { |
|
|
|
@ -48,8 +138,6 @@ MiddlewareRegistry.register(store => next => action => { |
|
|
|
|
} |
|
|
|
|
case PARTICIPANT_LEFT: { |
|
|
|
|
if (!joinLeaveNotificationsDisabled()) { |
|
|
|
|
const { dispatch, getState } = store; |
|
|
|
|
const state = getState(); |
|
|
|
|
const participant = getParticipantById( |
|
|
|
|
store.getState(), |
|
|
|
|
action.participant.id |
|
|
|
@ -65,7 +153,6 @@ MiddlewareRegistry.register(store => next => action => { |
|
|
|
|
return next(action); |
|
|
|
|
} |
|
|
|
|
case PARTICIPANT_UPDATED: { |
|
|
|
|
const state = store.getState(); |
|
|
|
|
const { disableModeratorIndicator } = state['features/base/config']; |
|
|
|
|
|
|
|
|
|
if (disableModeratorIndicator) { |
|
|
|
@ -93,7 +180,7 @@ MiddlewareRegistry.register(store => next => action => { |
|
|
|
|
return next(action); |
|
|
|
|
} |
|
|
|
|
case PARTICIPANTS_PANE_OPEN: { |
|
|
|
|
store.dispatch(hideRaiseHandNotifications()); |
|
|
|
|
store.dispatch(hideNotification(RAISE_HAND_NOTIFICATION_ID)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|