bigbuffet-rw/app/soapbox/reducers/chat_messages.js

19 lines
548 B
JavaScript
Raw Normal View History

2020-08-25 19:31:34 -07:00
import {
CHAT_MESSAGES_FETCH_SUCCESS,
CHAT_MESSAGE_SEND_SUCCESS,
} from 'soapbox/actions/chats';
2020-08-25 18:33:49 -07:00
import { Map as ImmutableMap, fromJS } from 'immutable';
const initialState = ImmutableMap();
export default function chatMessages(state = initialState, action) {
switch(action.type) {
case CHAT_MESSAGES_FETCH_SUCCESS:
return state.set(action.chatId, fromJS(action.data));
2020-08-25 19:31:34 -07:00
case CHAT_MESSAGE_SEND_SUCCESS:
return state.set(action.chatId, state.get(action.chatId).insert(0, fromJS(action.data)));
2020-08-25 18:33:49 -07:00
default:
return state;
}
};