2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { ReducerRegistry } from '../base/redux';
|
|
|
|
|
|
|
|
import {
|
|
|
|
TOGGLE_REACTIONS_VISIBLE,
|
2021-07-20 11:31:49 +00:00
|
|
|
SET_REACTION_QUEUE,
|
|
|
|
ADD_REACTION_BUFFER,
|
2021-08-23 09:57:56 +00:00
|
|
|
FLUSH_REACTION_BUFFER,
|
|
|
|
SHOW_SOUNDS_NOTIFICATION
|
2021-07-13 06:50:08 +00:00
|
|
|
} from './actionTypes';
|
2022-06-08 07:44:47 +00:00
|
|
|
import { ReactionEmojiProps } from './constants';
|
|
|
|
|
2022-07-11 12:30:37 +00:00
|
|
|
interface IReactionsState {
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* An array that contains the reactions buffer to be sent.
|
|
|
|
*/
|
|
|
|
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-07-20 08:47:01 +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.
|
|
|
|
*/
|
|
|
|
queue: Array<ReactionEmojiProps>,
|
|
|
|
|
|
|
|
/**
|
2022-07-20 08:47:01 +00:00
|
|
|
* A number, non-zero value which identifies the timer created by a call
|
|
|
|
* to setTimeout().
|
|
|
|
*/
|
|
|
|
timeoutID: number|null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The indicator that determines whether the reactions menu is visible.
|
2022-06-08 07:44:47 +00:00
|
|
|
*/
|
2022-07-20 08:47:01 +00:00
|
|
|
visible: boolean
|
2022-06-08 07:44:47 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 12:30:37 +00:00
|
|
|
export interface ReactionsAction extends Partial<IReactionsState> {
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The message to be added to the chat.
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
reactions?: Array<string>,
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
/**
|
|
|
|
* The action type.
|
|
|
|
*/
|
|
|
|
type: string
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ReducerRegistry.register(
|
|
|
|
'features/reactions',
|
2022-07-11 12:30:37 +00:00
|
|
|
(state: IReactionsState = _getInitialState(), action: ReactionsAction) => {
|
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,
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer: action.buffer,
|
2021-07-13 06:50:08 +00:00
|
|
|
timeoutID: action.timeoutID
|
|
|
|
};
|
|
|
|
|
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-06-08 07:44:47 +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;
|
|
|
|
});
|