2020-12-03 04:22:51 +00:00
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable'
|
2020-11-25 21:22:37 +00:00
|
|
|
import {
|
2020-12-03 04:22:51 +00:00
|
|
|
CHAT_MESSAGES_SEND_SUCCESS,
|
|
|
|
CHAT_MESSAGES_DELETE_REQUEST,
|
2020-12-16 00:31:30 +00:00
|
|
|
CHAT_MESSAGES_PURGE_REQUEST,
|
2020-12-03 04:22:51 +00:00
|
|
|
} from '../actions/chat_messages'
|
2020-11-25 21:22:37 +00:00
|
|
|
import {
|
2020-12-03 04:22:51 +00:00
|
|
|
CHAT_MESSAGES_IMPORT,
|
|
|
|
} from '../actions/importer'
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const importChatMessage = (state, chatMessage) => state.set(chatMessage.id, fromJS(chatMessage))
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const importChatMessages = (state, chatMessages) =>
|
|
|
|
state.withMutations((mutable) => chatMessages.forEach((chatMessage) => importChatMessage(mutable, chatMessage)))
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const deleteChatMessage = (state, id) => {
|
|
|
|
return state.delete(id)
|
|
|
|
}
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const initialState = ImmutableMap()
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
export default function chat_messages(state = initialState, action) {
|
2020-11-25 21:22:37 +00:00
|
|
|
switch(action.type) {
|
2020-12-03 04:22:51 +00:00
|
|
|
case CHAT_MESSAGES_IMPORT:
|
|
|
|
return importChatMessages(state, action.chatMessages)
|
|
|
|
case CHAT_MESSAGES_SEND_SUCCESS:
|
|
|
|
return importChatMessage(state, action.chatMessage)
|
|
|
|
case CHAT_MESSAGES_DELETE_REQUEST:
|
|
|
|
return deleteChatMessage(state, action.chatMessageId)
|
2020-12-16 00:31:30 +00:00
|
|
|
case CHAT_MESSAGES_PURGE_REQUEST:
|
|
|
|
return state
|
2020-11-25 21:22:37 +00:00
|
|
|
default:
|
2020-12-03 04:22:51 +00:00
|
|
|
return state
|
2020-11-25 21:22:37 +00:00
|
|
|
}
|
2020-12-03 04:22:51 +00:00
|
|
|
}
|