2019-09-05 07:31:36 +00:00
|
|
|
import authAPI from '../../../api/auth';
|
|
|
|
|
|
|
|
export const getSelectedChatConversation = ({
|
|
|
|
allConversations,
|
|
|
|
selectedChat,
|
|
|
|
}) =>
|
|
|
|
allConversations.filter(conversation => conversation.id === selectedChat.id);
|
|
|
|
|
|
|
|
// getters
|
|
|
|
const getters = {
|
|
|
|
getAllConversations: ({ allConversations }) => allConversations,
|
|
|
|
getSelectedChat: ({ selectedChat }) => selectedChat,
|
|
|
|
getMineChats(_state) {
|
|
|
|
const currentUserID = authAPI.getCurrentUser().id;
|
|
|
|
return _state.allConversations.filter(chat =>
|
|
|
|
chat.meta.assignee === null
|
|
|
|
? false
|
|
|
|
: chat.status === _state.chatStatusFilter &&
|
|
|
|
chat.meta.assignee.id === currentUserID
|
|
|
|
);
|
|
|
|
},
|
|
|
|
getUnAssignedChats(_state) {
|
|
|
|
return _state.allConversations.filter(
|
|
|
|
chat =>
|
|
|
|
chat.meta.assignee === null && chat.status === _state.chatStatusFilter
|
|
|
|
);
|
|
|
|
},
|
|
|
|
getAllStatusChats(_state) {
|
|
|
|
return _state.allConversations.filter(
|
|
|
|
chat => chat.status === _state.chatStatusFilter
|
|
|
|
);
|
|
|
|
},
|
|
|
|
getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus,
|
|
|
|
getAllMessagesLoaded(_state) {
|
|
|
|
const [chat] = getSelectedChatConversation(_state);
|
2020-03-08 16:38:25 +00:00
|
|
|
return !chat || chat.allMessagesLoaded === undefined
|
2019-09-05 07:31:36 +00:00
|
|
|
? false
|
|
|
|
: chat.allMessagesLoaded;
|
|
|
|
},
|
|
|
|
getUnreadCount(_state) {
|
|
|
|
const [chat] = getSelectedChatConversation(_state);
|
2020-03-08 16:38:25 +00:00
|
|
|
if (!chat) return [];
|
2019-09-05 07:31:36 +00:00
|
|
|
return chat.messages.filter(
|
|
|
|
chatMessage =>
|
|
|
|
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&
|
2020-02-22 14:46:56 +00:00
|
|
|
chatMessage.message_type === 0 &&
|
|
|
|
chatMessage.private !== true
|
2019-09-05 07:31:36 +00:00
|
|
|
).length;
|
|
|
|
},
|
|
|
|
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
|
|
|
|
getSelectedInbox: ({ currentInbox }) => currentInbox,
|
2019-12-01 04:46:51 +00:00
|
|
|
getConvTabStats: ({ convTabStats }) => convTabStats,
|
2019-09-05 07:31:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default getters;
|