2022-07-27 09:56:07 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
import {
|
2021-07-20 11:31:49 +00:00
|
|
|
ADD_REACTION_BUFFER,
|
2021-08-23 09:57:56 +00:00
|
|
|
FLUSH_REACTION_BUFFER,
|
2022-09-27 07:10:28 +00:00
|
|
|
SET_REACTION_QUEUE,
|
|
|
|
SHOW_SOUNDS_NOTIFICATION,
|
|
|
|
TOGGLE_REACTIONS_VISIBLE
|
2021-07-13 06:50:08 +00:00
|
|
|
} from './actionTypes';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReactionEmojiProps } from './constants';
|
2022-06-08 07:44:47 +00:00
|
|
|
|
2022-08-26 09:54:16 +00:00
|
|
|
export interface IReactionsState {
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* An array that contains the reactions buffer to be sent.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
buffer: Array<string>;
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
2022-07-20 08:47:01 +00:00
|
|
|
* Whether or not the disable reaction sounds notification was shown.
|
2022-06-08 07:44:47 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
notificationDisplayed: boolean;
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The array of reactions to animate.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
queue: Array<IReactionEmojiProps>;
|
2022-06-08 07:44:47 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-20 08:47:01 +00:00
|
|
|
* A number, non-zero value which identifies the timer created by a call
|
|
|
|
* to setTimeout().
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
timeoutID: number | null;
|
2022-07-20 08:47:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The indicator that determines whether the reactions menu is visible.
|
2022-06-08 07:44:47 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
visible: boolean;
|
2022-06-08 07:44:47 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
export interface IReactionsAction extends Partial<IReactionsState> {
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The message to be added to the chat.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
message?: string;
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The reaction to be added to buffer.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
reaction?: string;
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The reactions to be added to the animation queue.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
reactions?: Array<string>;
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The action type.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
type: string;
|
2022-06-08 07:44:47 +00:00
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns initial state for reactions' part of Redux store.
|
|
|
|
*
|
|
|
|
* @private
|
2022-07-11 12:30:37 +00:00
|
|
|
* @returns {IReactionsState}
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2022-07-11 12:30:37 +00:00
|
|
|
function _getInitialState(): IReactionsState {
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
visible: false,
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer: [],
|
2021-07-13 06:50:08 +00:00
|
|
|
timeoutID: null,
|
2021-08-23 09:57:56 +00:00
|
|
|
queue: [],
|
|
|
|
notificationDisplayed: false
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IReactionsState>(
|
2021-07-13 06:50:08 +00:00
|
|
|
'features/reactions',
|
2022-10-20 09:11:27 +00:00
|
|
|
(state = _getInitialState(), action: IReactionsAction): IReactionsState => {
|
2021-07-13 06:50:08 +00:00
|
|
|
switch (action.type) {
|
|
|
|
|
|
|
|
case TOGGLE_REACTIONS_VISIBLE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
visible: !state.visible
|
|
|
|
};
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case ADD_REACTION_BUFFER:
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-09-05 09:05:07 +00:00
|
|
|
buffer: action.buffer ?? [],
|
|
|
|
timeoutID: action.timeoutID ?? null
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case FLUSH_REACTION_BUFFER:
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer: [],
|
2021-07-13 06:50:08 +00:00
|
|
|
timeoutID: null
|
|
|
|
};
|
|
|
|
|
|
|
|
case SET_REACTION_QUEUE: {
|
|
|
|
return {
|
|
|
|
...state,
|
2022-09-05 09:05:07 +00:00
|
|
|
queue: action.queue ?? []
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
2021-08-23 09:57:56 +00:00
|
|
|
|
|
|
|
case SHOW_SOUNDS_NOTIFICATION: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
notificationDisplayed: true
|
|
|
|
};
|
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|