36 lines
904 B
JavaScript
36 lines
904 B
JavaScript
|
import { LOGIN_SUCCESS, LOGIN_FAILURE } from '../actions/login';
|
||
|
import { FETCH_MESSAGES_SUCCESS } from '../actions/chat';
|
||
|
|
||
|
const defaultState = {
|
||
|
messagesByChannel: {},
|
||
|
}
|
||
|
|
||
|
export default function chatReducer(state = defaultState, action) {
|
||
|
switch (action.type) {
|
||
|
case FETCH_MESSAGES_SUCCESS:
|
||
|
return {
|
||
|
...state,
|
||
|
messagesByChannel: {
|
||
|
...state.messagesByChannel,
|
||
|
[action.channel]: [...action.data.Messages]
|
||
|
}
|
||
|
};
|
||
|
case 'CHANNEL_EVENT':
|
||
|
switch(action.event) {
|
||
|
case "message":
|
||
|
return {
|
||
|
...state,
|
||
|
messagesByChannel: {
|
||
|
...state.messagesByChannel,
|
||
|
[action.data.Channel]: [
|
||
|
...state.messagesByChannel[action.data.Channel],
|
||
|
action.data.Message
|
||
|
]
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return state;
|
||
|
}
|
||
|
return state;
|
||
|
}
|