Rev 5307 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import { chatActionTypes } from './chat.types'
const initialState = {
messages: [],
currentPage: 1,
lastPage: 1,
loading: false,
conversation: {}
}
export default (state = initialState, { type, payload }) => {
switch (type) {
case 'sendMessage':
return {
...state,
messages: [
...state.messages,
{
...payload,
not_received: !state.conversation.online
}
]
}
case chatActionTypes.SET_UNREAD_MESSAGES:
if (JSON.stringify(payload) !== JSON.stringify(state.unreadMessages)) {
// let newShouldAlertNewMessage;
return {
...state,
unreadMessages: payload,
haveNewMessage: true
}
} else {
return state
}
case chatActionTypes.SET_NEW_MESSAGE:
return { ...state, haveNewMessage: payload }
case chatActionTypes.SET_SHOULD_ALERT_NEW_MESSAGE:
return { ...state, shouldAlertNewMessage: payload }
default:
return state
}
}