2021-07-13 06:50:08 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
import { batch } from 'react-redux';
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
import { ENDPOINT_REACTION_NAME } from '../../../modules/API/constants';
|
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2021-07-20 08:58:42 +00:00
|
|
|
import { isVpaasMeeting } from '../jaas/functions';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
import {
|
2021-07-20 11:31:49 +00:00
|
|
|
ADD_REACTION_BUFFER,
|
|
|
|
FLUSH_REACTION_BUFFER,
|
|
|
|
SEND_REACTIONS,
|
|
|
|
PUSH_REACTIONS
|
2021-07-13 06:50:08 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
import {
|
2021-07-20 11:31:49 +00:00
|
|
|
addReactionsToChat,
|
|
|
|
flushReactionBuffer,
|
|
|
|
pushReactions,
|
|
|
|
sendReactions,
|
2021-07-13 06:50:08 +00:00
|
|
|
setReactionQueue
|
|
|
|
} from './actions.any';
|
2021-07-20 11:31:49 +00:00
|
|
|
import { getReactionMessageFromBuffer, getReactionsWithId, sendReactionsWebhook } from './functions.any';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware which intercepts Reactions actions to handle changes to the
|
|
|
|
* visibility timeout of the Reactions.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
const { dispatch, getState } = store;
|
|
|
|
|
|
|
|
switch (action.type) {
|
2021-07-20 11:31:49 +00:00
|
|
|
case ADD_REACTION_BUFFER: {
|
|
|
|
const { timeoutID, buffer } = getState()['features/reactions'];
|
2021-07-13 06:50:08 +00:00
|
|
|
const { reaction } = action;
|
|
|
|
|
|
|
|
clearTimeout(timeoutID);
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer.push(reaction);
|
|
|
|
action.buffer = buffer;
|
2021-07-13 06:50:08 +00:00
|
|
|
action.timeoutID = setTimeout(() => {
|
2021-07-20 11:31:49 +00:00
|
|
|
dispatch(flushReactionBuffer());
|
2021-07-13 06:50:08 +00:00
|
|
|
}, 500);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case FLUSH_REACTION_BUFFER: {
|
2021-07-15 12:23:48 +00:00
|
|
|
const state = getState();
|
2021-07-20 11:31:49 +00:00
|
|
|
const { buffer } = state['features/reactions'];
|
|
|
|
|
|
|
|
batch(() => {
|
|
|
|
dispatch(sendReactions());
|
|
|
|
dispatch(addReactionsToChat(getReactionMessageFromBuffer(buffer)));
|
|
|
|
dispatch(pushReactions(buffer));
|
|
|
|
});
|
2021-07-15 12:23:48 +00:00
|
|
|
|
|
|
|
if (isVpaasMeeting(state)) {
|
2021-07-20 11:31:49 +00:00
|
|
|
sendReactionsWebhook(state, buffer);
|
2021-07-15 12:23:48 +00:00
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case SEND_REACTIONS: {
|
|
|
|
const state = getState();
|
|
|
|
const { buffer } = state['features/reactions'];
|
2021-07-13 06:50:08 +00:00
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (conference) {
|
|
|
|
conference.sendEndpointMessage('', {
|
|
|
|
name: ENDPOINT_REACTION_NAME,
|
2021-07-20 11:31:49 +00:00
|
|
|
reactions: buffer,
|
2021-07-13 06:50:08 +00:00
|
|
|
timestamp: Date.now()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case PUSH_REACTIONS: {
|
2021-07-13 06:50:08 +00:00
|
|
|
const queue = store.getState()['features/reactions'].queue;
|
2021-07-20 11:31:49 +00:00
|
|
|
const reactions = action.reactions;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
dispatch(setReactionQueue([ ...queue, ...getReactionsWithId(reactions) ]));
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|