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

19 lines
535 B
JavaScript
Raw Normal View History

import { CHATS_IMPORT } from 'soapbox/actions/importer';
2020-08-24 19:26:42 -07:00
import { Map as ImmutableMap, fromJS } from 'immutable';
2020-08-25 10:38:21 -07:00
const importChat = (state, chat) => state.set(chat.id, fromJS(chat));
const importChats = (state, chats) =>
state.withMutations(mutable => chats.forEach(chat => importChat(mutable, chat)));
2020-08-24 19:26:42 -07:00
const initialState = ImmutableMap();
2020-08-25 18:33:49 -07:00
export default function chats(state = initialState, action) {
2020-08-24 19:26:42 -07:00
switch(action.type) {
2020-08-25 10:38:21 -07:00
case CHATS_IMPORT:
return importChats(state, action.chats);
2020-08-24 19:26:42 -07:00
default:
return state;
}
};