Chore: Events Cleanup (#739)
* Chore: Events Cleanup - fix failing tests - add additional webhook events - clean up event logic * Fix conversation status update in action cable Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -8,7 +8,8 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
'message.created': this.onMessageCreated,
|
||||
'message.updated': this.onMessageUpdated,
|
||||
'conversation.created': this.onConversationCreated,
|
||||
'status_change:conversation': this.onStatusChange,
|
||||
'conversation.opened': this.onStatusChange,
|
||||
'conversation.resolved': this.onStatusChange,
|
||||
'user:logout': this.onLogout,
|
||||
'page:reload': this.onReload,
|
||||
'assignee.changed': this.onAssigneeChanged,
|
||||
@@ -40,7 +41,7 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||
onReload = () => window.location.reload();
|
||||
|
||||
onStatusChange = data => {
|
||||
this.app.$store.dispatch('addConversation', data);
|
||||
this.app.$store.dispatch('updateConversation', data);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -149,8 +149,15 @@ const actions = {
|
||||
commit(types.default.ADD_MESSAGE, message);
|
||||
},
|
||||
|
||||
addConversation({ commit }, conversation) {
|
||||
commit(types.default.ADD_CONVERSATION, conversation);
|
||||
addConversation({ commit, state }, conversation) {
|
||||
const { currentInbox } = state;
|
||||
if (!currentInbox || Number(currentInbox) === conversation.inbox_id) {
|
||||
commit(types.default.ADD_CONVERSATION, conversation);
|
||||
}
|
||||
},
|
||||
|
||||
updateConversation({ commit }, conversation) {
|
||||
commit(types.default.UPDATE_CONVERSATION, conversation);
|
||||
},
|
||||
|
||||
toggleTyping: async ({ commit }, { status, inboxId, contactId }) => {
|
||||
|
||||
@@ -153,6 +153,24 @@ const mutations = {
|
||||
_state.allConversations.push(conversation);
|
||||
},
|
||||
|
||||
[types.default.UPDATE_CONVERSATION](_state, conversation) {
|
||||
const { allConversations } = _state;
|
||||
const currentConversationIndex = allConversations.findIndex(
|
||||
c => c.id === conversation.id
|
||||
);
|
||||
if (currentConversationIndex > -1) {
|
||||
const currentConversation = {
|
||||
...allConversations[currentConversationIndex],
|
||||
status: conversation.status,
|
||||
};
|
||||
Vue.set(allConversations, currentConversationIndex, currentConversation);
|
||||
if (_state.selectedChat.id === conversation.id) {
|
||||
_state.selectedChat.status = conversation.status;
|
||||
window.bus.$emit('scrollToMessage');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
[types.default.MARK_SEEN](_state) {
|
||||
_state.selectedChat.seen = true;
|
||||
},
|
||||
|
||||
@@ -21,6 +21,7 @@ export default {
|
||||
CLEAR_ALL_MESSAGES: 'CLEAR_ALL_MESSAGES',
|
||||
RESOLVE_CONVERSATION: 'RESOLVE_CONVERSATION',
|
||||
ADD_CONVERSATION: 'ADD_CONVERSATION',
|
||||
UPDATE_CONVERSATION: 'UPDATE_CONVERSATION',
|
||||
SEND_MESSAGE: 'SEND_MESSAGE',
|
||||
ASSIGN_AGENT: 'ASSIGN_AGENT',
|
||||
SET_CHAT_META: 'SET_CHAT_META',
|
||||
|
||||
Reference in New Issue
Block a user