2020-12-03 04:22:51 +00:00
|
|
|
import {
|
|
|
|
Map as ImmutableMap,
|
|
|
|
List as ImmutableList,
|
|
|
|
fromJS,
|
|
|
|
} from 'immutable'
|
|
|
|
import { me } from '../initial_state'
|
|
|
|
import {
|
|
|
|
CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS_SUCCESS,
|
2020-12-16 22:29:06 +00:00
|
|
|
CLEAR_CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS,
|
2020-12-03 04:22:51 +00:00
|
|
|
SET_CHAT_CONVERSATION_SELECTED,
|
|
|
|
} from '../actions/chats'
|
|
|
|
import {
|
2020-12-03 22:13:11 +00:00
|
|
|
CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS,
|
2020-12-03 04:22:51 +00:00
|
|
|
CHAT_CONVERSATION_REQUESTED_COUNT_FETCH_SUCCESS,
|
2020-12-16 00:31:30 +00:00
|
|
|
CHAT_CONVERSATION_MARK_READ_FETCH,
|
2020-12-03 04:22:51 +00:00
|
|
|
} from '../actions/chat_conversations'
|
|
|
|
import {
|
|
|
|
CHAT_MESSAGES_FETCH_SUCCESS,
|
|
|
|
CHAT_CONVERSATION_MESSAGES_EXPAND_SUCCESS,
|
|
|
|
} from '../actions/chat_messages'
|
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
|
|
|
createChatConversationSuggestionIds: ImmutableList(),
|
|
|
|
selectedChatConversationId: null,
|
|
|
|
chatConversationRequestCount: 0,
|
2020-12-03 22:13:11 +00:00
|
|
|
chatsUnreadCount: 0,
|
2020-12-03 04:22:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
export default function chats(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS_SUCCESS:
|
|
|
|
return state.set('createChatConversationSuggestionIds', ImmutableList(action.accounts.map((item) => item.id)))
|
2020-12-16 22:29:06 +00:00
|
|
|
case CLEAR_CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS:
|
|
|
|
return state.set('createChatConversationSuggestionIds', ImmutableList())
|
2020-12-03 04:22:51 +00:00
|
|
|
case SET_CHAT_CONVERSATION_SELECTED:
|
|
|
|
return state.set('selectedChatConversationId', action.chatConversationId)
|
|
|
|
case CHAT_CONVERSATION_REQUESTED_COUNT_FETCH_SUCCESS:
|
|
|
|
return state.set('chatConversationRequestCount', action.count)
|
2020-12-03 22:13:11 +00:00
|
|
|
case CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS:
|
|
|
|
return state.set('chatsUnreadCount', action.count)
|
2020-12-16 00:31:30 +00:00
|
|
|
case CHAT_CONVERSATION_MARK_READ_FETCH:
|
|
|
|
const chatConversationUnreadCount = action.chatConversation.get('unread_count')
|
|
|
|
const totalUnreadCount = state.get('chatsUnreadCount')
|
|
|
|
return state.set('chatsUnreadCount', Math.max(totalUnreadCount - chatConversationUnreadCount, 0))
|
2020-12-03 04:22:51 +00:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|