2018-02-19 21:19:39 +00:00
|
|
|
import { STARRED_MESSAGES } from '../actions/actionsTypes';
|
|
|
|
|
|
|
|
const initialState = {
|
2018-03-02 15:11:34 +00:00
|
|
|
messages: [],
|
|
|
|
isOpen: false
|
2018-02-19 21:19:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function server(state = initialState, action) {
|
|
|
|
switch (action.type) {
|
2018-03-02 15:11:34 +00:00
|
|
|
case STARRED_MESSAGES.OPEN:
|
2018-02-19 21:19:39 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2018-03-02 15:11:34 +00:00
|
|
|
isOpen: true
|
|
|
|
};
|
|
|
|
case STARRED_MESSAGES.MESSAGES_RECEIVED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messages: [...state.messages, ...action.messages]
|
2018-02-19 21:19:39 +00:00
|
|
|
};
|
|
|
|
case STARRED_MESSAGES.MESSAGE_UNSTARRED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messages: state.messages.filter(message => message._id !== action.messageId)
|
|
|
|
};
|
|
|
|
case STARRED_MESSAGES.CLOSE:
|
|
|
|
return initialState;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|