2022-02-18 13:46:19 +00:00
|
|
|
import { TActionsRoom } from '../actions/room';
|
2020-03-06 13:13:24 +00:00
|
|
|
import { ROOM } from '../actions/actionsTypes';
|
|
|
|
|
2022-02-18 13:46:19 +00:00
|
|
|
export type IRoomRecord = string[];
|
|
|
|
|
|
|
|
export interface IRoom {
|
|
|
|
rid: string;
|
|
|
|
isDeleting: boolean;
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: string;
|
2023-01-13 19:32:52 +00:00
|
|
|
historyLoaders: string[];
|
2022-02-18 13:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const initialState: IRoom = {
|
|
|
|
rid: '',
|
2020-04-30 17:53:35 +00:00
|
|
|
isDeleting: false,
|
2023-01-13 19:32:52 +00:00
|
|
|
subscribedRoom: '',
|
|
|
|
historyLoaders: []
|
2020-03-06 13:13:24 +00:00
|
|
|
};
|
|
|
|
|
2022-02-18 13:46:19 +00:00
|
|
|
export default function (state = initialState, action: TActionsRoom): IRoom {
|
2020-03-06 13:13:24 +00:00
|
|
|
switch (action.type) {
|
2020-04-30 17:53:35 +00:00
|
|
|
case ROOM.SUBSCRIBE:
|
|
|
|
return {
|
|
|
|
...state,
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: action.rid
|
2020-04-30 17:53:35 +00:00
|
|
|
};
|
|
|
|
case ROOM.UNSUBSCRIBE:
|
|
|
|
return {
|
|
|
|
...state,
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: state.subscribedRoom === action.rid ? '' : state.subscribedRoom
|
2020-04-30 17:53:35 +00:00
|
|
|
};
|
2020-03-20 16:38:01 +00:00
|
|
|
case ROOM.LEAVE:
|
2020-03-06 13:13:24 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2021-06-07 16:18:14 +00:00
|
|
|
rid: action.room.rid,
|
2020-03-06 13:13:24 +00:00
|
|
|
isDeleting: true
|
|
|
|
};
|
2020-03-20 16:38:01 +00:00
|
|
|
case ROOM.DELETE:
|
|
|
|
return {
|
|
|
|
...state,
|
2021-07-02 19:13:41 +00:00
|
|
|
rid: action.room.rid,
|
2020-03-20 16:38:01 +00:00
|
|
|
isDeleting: true
|
|
|
|
};
|
2020-05-08 17:36:10 +00:00
|
|
|
case ROOM.CLOSE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
rid: action.rid,
|
|
|
|
isDeleting: true
|
|
|
|
};
|
|
|
|
case ROOM.FORWARD:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
rid: action.rid,
|
|
|
|
isDeleting: true
|
|
|
|
};
|
2020-03-20 16:38:01 +00:00
|
|
|
case ROOM.REMOVED:
|
2020-03-06 13:13:24 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isDeleting: false
|
|
|
|
};
|
2023-01-13 19:32:52 +00:00
|
|
|
case ROOM.HISTORY_REQUEST:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
historyLoaders: [...state.historyLoaders, action.loaderId]
|
|
|
|
};
|
|
|
|
case ROOM.HISTORY_FINISHED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
historyLoaders: state.historyLoaders.filter(loaderId => loaderId !== action.loaderId)
|
|
|
|
};
|
2020-03-06 13:13:24 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|