2023-02-23 20:59:00 +00:00
|
|
|
import { batch } from 'react-redux';
|
2022-11-22 13:56:37 +00:00
|
|
|
import { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
import { IStore } from '../app/types';
|
2021-09-09 22:46:41 +00:00
|
|
|
import {
|
|
|
|
PARTICIPANT_JOINED,
|
|
|
|
PARTICIPANT_KICKED,
|
|
|
|
PARTICIPANT_LEFT,
|
|
|
|
PARTICIPANT_UPDATED
|
|
|
|
} from '../base/participants/actionTypes';
|
2022-10-26 06:59:21 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2021-09-09 22:46:41 +00:00
|
|
|
|
2021-11-10 17:49:53 +00:00
|
|
|
import {
|
2022-11-22 13:56:37 +00:00
|
|
|
ADD_TO_OFFSET,
|
2021-11-10 17:49:53 +00:00
|
|
|
INIT_SEARCH,
|
2021-12-28 14:35:21 +00:00
|
|
|
INIT_UPDATE_STATS,
|
|
|
|
RESET_SEARCH_CRITERIA
|
2021-11-10 17:49:53 +00:00
|
|
|
} from './actionTypes';
|
2022-11-22 13:56:37 +00:00
|
|
|
import {
|
|
|
|
clearTimelineBoundary,
|
|
|
|
initReorderStats,
|
|
|
|
setTimelineBoundary,
|
|
|
|
updateSortedSpeakerStatsIds,
|
|
|
|
updateStats
|
|
|
|
} from './actions.any';
|
|
|
|
import { CLEAR_TIME_BOUNDARY_THRESHOLD } from './constants';
|
|
|
|
import {
|
|
|
|
filterBySearchCriteria,
|
|
|
|
getCurrentDuration,
|
|
|
|
getPendingReorder,
|
|
|
|
getSortedSpeakerStatsIds,
|
|
|
|
getTimelineBoundaries,
|
|
|
|
resetHiddenStats
|
|
|
|
} from './functions';
|
2021-09-09 22:46:41 +00:00
|
|
|
|
2022-11-22 13:56:37 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }: IStore) => (next: Function) => (action: AnyAction) => {
|
2021-09-09 22:46:41 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case INIT_SEARCH: {
|
|
|
|
const state = getState();
|
|
|
|
const stats = filterBySearchCriteria(state);
|
|
|
|
|
|
|
|
dispatch(updateStats(stats));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case INIT_UPDATE_STATS:
|
|
|
|
if (action.getSpeakerStats) {
|
|
|
|
const state = getState();
|
|
|
|
const speakerStats = { ...action.getSpeakerStats() };
|
|
|
|
const stats = filterBySearchCriteria(state, speakerStats);
|
|
|
|
const pendingReorder = getPendingReorder(state);
|
|
|
|
|
2023-02-23 20:59:00 +00:00
|
|
|
batch(() => {
|
|
|
|
if (pendingReorder) {
|
|
|
|
dispatch(updateSortedSpeakerStatsIds(getSortedSpeakerStatsIds(state, stats) ?? []));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(updateStats(stats));
|
|
|
|
});
|
2022-09-28 07:51:53 +00:00
|
|
|
|
2021-09-09 22:46:41 +00:00
|
|
|
}
|
2022-09-28 07:51:53 +00:00
|
|
|
|
2021-09-09 22:46:41 +00:00
|
|
|
break;
|
2021-12-28 14:35:21 +00:00
|
|
|
|
|
|
|
case RESET_SEARCH_CRITERIA: {
|
|
|
|
const state = getState();
|
|
|
|
const stats = resetHiddenStats(state);
|
|
|
|
|
|
|
|
dispatch(updateStats(stats));
|
|
|
|
break;
|
|
|
|
}
|
2021-09-09 22:46:41 +00:00
|
|
|
case PARTICIPANT_JOINED:
|
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
case PARTICIPANT_KICKED:
|
|
|
|
case PARTICIPANT_UPDATED: {
|
2023-02-23 21:00:22 +00:00
|
|
|
const { pendingReorder } = getState()['features/speaker-stats'];
|
2021-09-09 22:46:41 +00:00
|
|
|
|
2023-02-23 21:00:22 +00:00
|
|
|
if (!pendingReorder) {
|
|
|
|
dispatch(initReorderStats());
|
|
|
|
}
|
2021-09-09 22:46:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-11-22 13:56:37 +00:00
|
|
|
|
|
|
|
case ADD_TO_OFFSET: {
|
|
|
|
const state = getState();
|
|
|
|
const { timelineBoundary } = state['features/speaker-stats'];
|
|
|
|
const { right } = getTimelineBoundaries(state);
|
|
|
|
const currentDuration = getCurrentDuration(state) ?? 0;
|
|
|
|
|
|
|
|
if (Math.abs((right + action.value) - currentDuration) < CLEAR_TIME_BOUNDARY_THRESHOLD) {
|
|
|
|
dispatch(clearTimelineBoundary());
|
|
|
|
} else if (!timelineBoundary) {
|
|
|
|
dispatch(setTimelineBoundary(currentDuration ?? 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-09-09 22:46:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 13:56:37 +00:00
|
|
|
return next(action);
|
2021-09-09 22:46:41 +00:00
|
|
|
});
|