eee89bf0d8
* Adds last emails to reply editor * Fixes bug in reply box * Adds test cases * Prevents private notes having cc bcc data * Prevents private notes having cc bcc data * Init reply head with values * fix broken tests Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
97 lines
3.3 KiB
JavaScript
97 lines
3.3 KiB
JavaScript
import authAPI from '../../../api/auth';
|
|
import { MESSAGE_TYPE } from 'shared/constants/messages';
|
|
import { applyPageFilters } from './helpers';
|
|
|
|
export const getSelectedChatConversation = ({
|
|
allConversations,
|
|
selectedChatId,
|
|
}) =>
|
|
allConversations.filter(conversation => conversation.id === selectedChatId);
|
|
|
|
// getters
|
|
const getters = {
|
|
getAllConversations: ({ allConversations }) =>
|
|
allConversations.sort(
|
|
(a, b) => b.messages.last()?.created_at - a.messages.last()?.created_at
|
|
),
|
|
getSelectedChat: ({ selectedChatId, allConversations }) => {
|
|
const selectedChat = allConversations.find(
|
|
conversation => conversation.id === selectedChatId
|
|
);
|
|
return selectedChat || {};
|
|
},
|
|
getLastEmailInSelectedChat: (stage, _getters) => {
|
|
const selectedChat = _getters.getSelectedChat;
|
|
const { messages = [] } = selectedChat;
|
|
const lastEmail = [...messages].reverse().find(message => {
|
|
const {
|
|
content_attributes: contentAttributes = {},
|
|
message_type: messageType,
|
|
} = message;
|
|
const { email = {} } = contentAttributes;
|
|
const isIncomingOrOutgoing =
|
|
messageType === MESSAGE_TYPE.OUTGOING ||
|
|
messageType === MESSAGE_TYPE.INCOMING;
|
|
if (email.from && isIncomingOrOutgoing) {
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
|
|
return lastEmail;
|
|
},
|
|
getMineChats: _state => activeFilters => {
|
|
const currentUserID = authAPI.getCurrentUser().id;
|
|
|
|
return _state.allConversations.filter(conversation => {
|
|
const { assignee } = conversation.meta;
|
|
const isAssignedToMe = assignee && assignee.id === currentUserID;
|
|
const shouldFilter = applyPageFilters(conversation, activeFilters);
|
|
const isChatMine = isAssignedToMe && shouldFilter;
|
|
|
|
return isChatMine;
|
|
});
|
|
},
|
|
getAppliedConversationFilters: _state => {
|
|
return _state.appliedFilters;
|
|
},
|
|
getUnAssignedChats: _state => activeFilters => {
|
|
return _state.allConversations.filter(conversation => {
|
|
const isUnAssigned = !conversation.meta.assignee;
|
|
const shouldFilter = applyPageFilters(conversation, activeFilters);
|
|
return isUnAssigned && shouldFilter;
|
|
});
|
|
},
|
|
getAllStatusChats: _state => activeFilters => {
|
|
return _state.allConversations.filter(conversation => {
|
|
const shouldFilter = applyPageFilters(conversation, activeFilters);
|
|
return shouldFilter;
|
|
});
|
|
},
|
|
getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus,
|
|
getAllMessagesLoaded(_state) {
|
|
const [chat] = getSelectedChatConversation(_state);
|
|
return !chat || chat.allMessagesLoaded === undefined
|
|
? false
|
|
: chat.allMessagesLoaded;
|
|
},
|
|
getUnreadCount(_state) {
|
|
const [chat] = getSelectedChatConversation(_state);
|
|
if (!chat) return [];
|
|
return chat.messages.filter(
|
|
chatMessage =>
|
|
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&
|
|
chatMessage.message_type === 0 &&
|
|
chatMessage.private !== true
|
|
).length;
|
|
},
|
|
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
|
|
getSelectedInbox: ({ currentInbox }) => currentInbox,
|
|
getConversationById: _state => conversationId => {
|
|
return _state.allConversations.find(
|
|
value => value.id === Number(conversationId)
|
|
);
|
|
},
|
|
};
|
|
|
|
export default getters;
|