Chore: Fix issues with conversation data models (#1000)
Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
parent
36661ea45d
commit
4612494923
15 changed files with 147 additions and 51 deletions
|
@ -7,7 +7,7 @@
|
||||||
<Thumbnail
|
<Thumbnail
|
||||||
v-if="!hideThumbnail"
|
v-if="!hideThumbnail"
|
||||||
:src="currentContact.thumbnail"
|
:src="currentContact.thumbnail"
|
||||||
:badge="currentContact.channel"
|
:badge="chatMetadata.channel"
|
||||||
class="columns"
|
class="columns"
|
||||||
:username="currentContact.name"
|
:username="currentContact.name"
|
||||||
:status="currentContact.availability_status"
|
:status="currentContact.availability_status"
|
||||||
|
@ -88,9 +88,13 @@ export default {
|
||||||
accountId: 'getCurrentAccountId',
|
accountId: 'getCurrentAccountId',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
chatMetadata() {
|
||||||
|
return this.chat.meta;
|
||||||
|
},
|
||||||
|
|
||||||
currentContact() {
|
currentContact() {
|
||||||
return this.$store.getters['contacts/getContact'](
|
return this.$store.getters['contacts/getContact'](
|
||||||
this.chat.meta.sender.id
|
this.chatMetadata.sender.id
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<Thumbnail
|
<Thumbnail
|
||||||
:src="currentContact.thumbnail"
|
:src="currentContact.thumbnail"
|
||||||
size="40px"
|
size="40px"
|
||||||
:badge="currentContact.channel"
|
:badge="chatMetadata.channel"
|
||||||
:username="currentContact.name"
|
:username="currentContact.name"
|
||||||
:status="currentContact.availability_status"
|
:status="currentContact.availability_status"
|
||||||
/>
|
/>
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
:allow-empty="true"
|
:allow-empty="true"
|
||||||
deselect-label="Remove"
|
deselect-label="Remove"
|
||||||
placeholder="Select Agent"
|
placeholder="Select Agent"
|
||||||
selected-label=""
|
selected-label
|
||||||
select-label="Assign"
|
select-label="Assign"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
@select="assignAgent"
|
@select="assignAgent"
|
||||||
|
@ -81,6 +81,10 @@ export default {
|
||||||
currentChat: 'getSelectedChat',
|
currentChat: 'getSelectedChat',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
chatMetadata() {
|
||||||
|
return this.chat.meta;
|
||||||
|
},
|
||||||
|
|
||||||
currentContact() {
|
currentContact() {
|
||||||
return this.$store.getters['contacts/getContact'](
|
return this.$store.getters['contacts/getContact'](
|
||||||
this.chat.meta.sender.id
|
this.chat.meta.sender.id
|
||||||
|
|
|
@ -121,23 +121,6 @@ export default {
|
||||||
);
|
);
|
||||||
return chat;
|
return chat;
|
||||||
},
|
},
|
||||||
// Get current FB Page ID
|
|
||||||
getPageId() {
|
|
||||||
let stateInbox;
|
|
||||||
if (this.inboxId) {
|
|
||||||
const inboxId = Number(this.inboxId);
|
|
||||||
[stateInbox] = this.inboxesList.filter(
|
|
||||||
inbox => inbox.channel_id === inboxId
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
[stateInbox] = this.inboxesList;
|
|
||||||
}
|
|
||||||
return !stateInbox ? 0 : stateInbox.page_id;
|
|
||||||
},
|
|
||||||
// Get current FB Page ID link
|
|
||||||
linkToMessage() {
|
|
||||||
return `https://m.me/${this.getPageId}`;
|
|
||||||
},
|
|
||||||
getReadMessages() {
|
getReadMessages() {
|
||||||
const chat = this.getMessages;
|
const chat = this.getMessages;
|
||||||
return chat === undefined ? null : this.readMessages(chat);
|
return chat === undefined ? null : this.readMessages(chat);
|
||||||
|
|
|
@ -121,12 +121,7 @@ export default {
|
||||||
currentChat: 'getSelectedChat',
|
currentChat: 'getSelectedChat',
|
||||||
}),
|
}),
|
||||||
channelType() {
|
channelType() {
|
||||||
const {
|
return this.currentChat.meta.channel;
|
||||||
meta: {
|
|
||||||
sender: { channel },
|
|
||||||
},
|
|
||||||
} = this.currentChat;
|
|
||||||
return channel;
|
|
||||||
},
|
},
|
||||||
conversationType() {
|
conversationType() {
|
||||||
const { additional_attributes: additionalAttributes } = this.currentChat;
|
const { additional_attributes: additionalAttributes } = this.currentChat;
|
||||||
|
@ -145,10 +140,7 @@ export default {
|
||||||
return 10000;
|
return 10000;
|
||||||
},
|
},
|
||||||
showFileUpload() {
|
showFileUpload() {
|
||||||
return (
|
return this.channelType === 'Channel::WebWidget';
|
||||||
this.channelType === 'Channel::WebWidget' ||
|
|
||||||
this.channelType === 'Channel::TwilioSms'
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
replyButtonLabel() {
|
replyButtonLabel() {
|
||||||
if (this.isPrivate) {
|
if (this.isPrivate) {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<thumbnail
|
<thumbnail
|
||||||
:src="contact.thumbnail"
|
:src="contact.thumbnail"
|
||||||
size="64px"
|
size="64px"
|
||||||
:badge="contact.channel"
|
:badge="channelType"
|
||||||
:username="contact.name"
|
:username="contact.name"
|
||||||
:status="contact.availability_status"
|
:status="contact.availability_status"
|
||||||
/>
|
/>
|
||||||
|
@ -158,6 +158,9 @@ export default {
|
||||||
} = this.browser;
|
} = this.browser;
|
||||||
return `${platformName || ''} ${platformVersion || ''}`;
|
return `${platformName || ''} ${platformVersion || ''}`;
|
||||||
},
|
},
|
||||||
|
channelType() {
|
||||||
|
return this.currentChat.meta?.channel;
|
||||||
|
},
|
||||||
contactId() {
|
contactId() {
|
||||||
return this.currentChat.meta?.sender?.id;
|
return this.currentChat.meta?.sender?.id;
|
||||||
},
|
},
|
||||||
|
|
|
@ -63,6 +63,10 @@ export const actions = {
|
||||||
updatePresence: ({ commit }, data) => {
|
updatePresence: ({ commit }, data) => {
|
||||||
commit(types.default.UPDATE_CONTACTS_PRESENCE, data);
|
commit(types.default.UPDATE_CONTACTS_PRESENCE, data);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setContact({ commit }, data) {
|
||||||
|
commit(types.default.SET_CONTACT_ITEM, data);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
|
|
|
@ -156,19 +156,24 @@ const actions = {
|
||||||
commit(types.default.ADD_MESSAGE, message);
|
commit(types.default.ADD_MESSAGE, message);
|
||||||
},
|
},
|
||||||
|
|
||||||
addConversation({ commit, state }, conversation) {
|
addConversation({ commit, state, dispatch }, conversation) {
|
||||||
const { currentInbox } = state;
|
const { currentInbox } = state;
|
||||||
if (!currentInbox || Number(currentInbox) === conversation.inbox_id) {
|
const {
|
||||||
|
inbox_id: inboxId,
|
||||||
|
meta: { sender },
|
||||||
|
} = conversation;
|
||||||
|
if (!currentInbox || Number(currentInbox) === inboxId) {
|
||||||
commit(types.default.ADD_CONVERSATION, conversation);
|
commit(types.default.ADD_CONVERSATION, conversation);
|
||||||
commit(
|
dispatch('contacts/setContact', sender);
|
||||||
`contacts/${types.default.SET_CONTACT_ITEM}`,
|
|
||||||
conversation.meta.sender
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateConversation({ commit }, conversation) {
|
updateConversation({ commit, dispatch }, conversation) {
|
||||||
|
const {
|
||||||
|
meta: { sender },
|
||||||
|
} = conversation;
|
||||||
commit(types.default.UPDATE_CONVERSATION, conversation);
|
commit(types.default.UPDATE_CONVERSATION, conversation);
|
||||||
|
dispatch('contacts/setContact', sender);
|
||||||
},
|
},
|
||||||
|
|
||||||
markMessagesRead: async ({ commit }, data) => {
|
markMessagesRead: async ({ commit }, data) => {
|
||||||
|
|
|
@ -140,9 +140,10 @@ const mutations = {
|
||||||
c => c.id === conversation.id
|
c => c.id === conversation.id
|
||||||
);
|
);
|
||||||
if (currentConversationIndex > -1) {
|
if (currentConversationIndex > -1) {
|
||||||
|
const { messages, ...conversationAttributes } = conversation;
|
||||||
const currentConversation = {
|
const currentConversation = {
|
||||||
...allConversations[currentConversationIndex],
|
...allConversations[currentConversationIndex],
|
||||||
...conversation,
|
...conversationAttributes,
|
||||||
};
|
};
|
||||||
Vue.set(allConversations, currentConversationIndex, currentConversation);
|
Vue.set(allConversations, currentConversationIndex, currentConversation);
|
||||||
if (_state.selectedChat.id === conversation.id) {
|
if (_state.selectedChat.id === conversation.id) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ jest.mock('axios');
|
||||||
|
|
||||||
describe('#actions', () => {
|
describe('#actions', () => {
|
||||||
describe('#get', () => {
|
describe('#get', () => {
|
||||||
it('sends correct actions if API is success', async () => {
|
it('sends correct mutations if API is success', async () => {
|
||||||
axios.get.mockResolvedValue({ data: { payload: contactList } });
|
axios.get.mockResolvedValue({ data: { payload: contactList } });
|
||||||
await actions.get({ commit });
|
await actions.get({ commit });
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
|
@ -18,7 +18,7 @@ describe('#actions', () => {
|
||||||
[types.default.SET_CONTACT_UI_FLAG, { isFetching: false }],
|
[types.default.SET_CONTACT_UI_FLAG, { isFetching: false }],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
it('sends correct actions if API is error', async () => {
|
it('sends correct mutations if API is error', async () => {
|
||||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||||
await actions.get({ commit });
|
await actions.get({ commit });
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
|
@ -29,7 +29,7 @@ describe('#actions', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#show', () => {
|
describe('#show', () => {
|
||||||
it('sends correct actions if API is success', async () => {
|
it('sends correct mutations if API is success', async () => {
|
||||||
axios.get.mockResolvedValue({ data: { payload: contactList[0] } });
|
axios.get.mockResolvedValue({ data: { payload: contactList[0] } });
|
||||||
await actions.show({ commit }, { id: contactList[0].id });
|
await actions.show({ commit }, { id: contactList[0].id });
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
|
@ -38,7 +38,7 @@ describe('#actions', () => {
|
||||||
[types.default.SET_CONTACT_UI_FLAG, { isFetchingItem: false }],
|
[types.default.SET_CONTACT_UI_FLAG, { isFetchingItem: false }],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
it('sends correct actions if API is error', async () => {
|
it('sends correct mutations if API is error', async () => {
|
||||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||||
await actions.show({ commit }, { id: contactList[0].id });
|
await actions.show({ commit }, { id: contactList[0].id });
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
|
@ -49,7 +49,7 @@ describe('#actions', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#update', () => {
|
describe('#update', () => {
|
||||||
it('sends correct actions if API is success', async () => {
|
it('sends correct mutations if API is success', async () => {
|
||||||
axios.patch.mockResolvedValue({ data: { payload: contactList[0] } });
|
axios.patch.mockResolvedValue({ data: { payload: contactList[0] } });
|
||||||
await actions.update({ commit }, contactList[0]);
|
await actions.update({ commit }, contactList[0]);
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
|
@ -69,4 +69,14 @@ describe('#actions', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#setContact', () => {
|
||||||
|
it('returns correct mutations', () => {
|
||||||
|
const data = { id: 1, name: 'john doe', availability_status: 'online' };
|
||||||
|
actions.setContact({ commit }, data);
|
||||||
|
expect(commit.mock.calls).toEqual([
|
||||||
|
[types.default.SET_CONTACT_ITEM, data],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ import actions from '../../conversations/actions';
|
||||||
import * as types from '../../../mutation-types';
|
import * as types from '../../../mutation-types';
|
||||||
|
|
||||||
const commit = jest.fn();
|
const commit = jest.fn();
|
||||||
|
const dispatch = jest.fn();
|
||||||
global.axios = axios;
|
global.axios = axios;
|
||||||
jest.mock('axios');
|
jest.mock('axios');
|
||||||
|
|
||||||
|
@ -39,4 +40,91 @@ describe('#actions', () => {
|
||||||
expect(commit.mock.calls).toEqual([]);
|
expect(commit.mock.calls).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#updateConversation', () => {
|
||||||
|
it('sends setContact action and update_conversation mutation', () => {
|
||||||
|
const conversation = {
|
||||||
|
id: 1,
|
||||||
|
messages: [],
|
||||||
|
meta: { sender: { id: 1, name: 'john-doe' } },
|
||||||
|
};
|
||||||
|
actions.updateConversation({ commit, dispatch }, conversation);
|
||||||
|
expect(commit.mock.calls).toEqual([
|
||||||
|
[types.default.UPDATE_CONVERSATION, conversation],
|
||||||
|
]);
|
||||||
|
expect(dispatch.mock.calls).toEqual([
|
||||||
|
[
|
||||||
|
'contacts/setContact',
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'john-doe',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addConversation', () => {
|
||||||
|
it('doesnot send mutation if conversation is from a different inbox', () => {
|
||||||
|
const conversation = {
|
||||||
|
id: 1,
|
||||||
|
messages: [],
|
||||||
|
meta: { sender: { id: 1, name: 'john-doe' } },
|
||||||
|
inbox_id: 2,
|
||||||
|
};
|
||||||
|
actions.addConversation(
|
||||||
|
{ commit, dispatch, state: { currentInbox: 1 } },
|
||||||
|
conversation
|
||||||
|
);
|
||||||
|
expect(commit.mock.calls).toEqual([]);
|
||||||
|
expect(dispatch.mock.calls).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sends correct mutations', () => {
|
||||||
|
const conversation = {
|
||||||
|
id: 1,
|
||||||
|
messages: [],
|
||||||
|
meta: { sender: { id: 1, name: 'john-doe' } },
|
||||||
|
inbox_id: 1,
|
||||||
|
};
|
||||||
|
actions.addConversation(
|
||||||
|
{ commit, dispatch, state: { currentInbox: 1 } },
|
||||||
|
conversation
|
||||||
|
);
|
||||||
|
expect(commit.mock.calls).toEqual([
|
||||||
|
[types.default.ADD_CONVERSATION, conversation],
|
||||||
|
]);
|
||||||
|
expect(dispatch.mock.calls).toEqual([
|
||||||
|
[
|
||||||
|
'contacts/setContact',
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'john-doe',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sends correct mutations if inbox filter is not available', () => {
|
||||||
|
const conversation = {
|
||||||
|
id: 1,
|
||||||
|
messages: [],
|
||||||
|
meta: { sender: { id: 1, name: 'john-doe' } },
|
||||||
|
inbox_id: 1,
|
||||||
|
};
|
||||||
|
actions.addConversation({ commit, dispatch, state: {} }, conversation);
|
||||||
|
expect(commit.mock.calls).toEqual([
|
||||||
|
[types.default.ADD_CONVERSATION, conversation],
|
||||||
|
]);
|
||||||
|
expect(dispatch.mock.calls).toEqual([
|
||||||
|
[
|
||||||
|
'contacts/setContact',
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'john-doe',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,7 +51,8 @@ class Notification < ApplicationRecord
|
||||||
read_at: read_at,
|
read_at: read_at,
|
||||||
secondary_actor: secondary_actor&.push_event_data,
|
secondary_actor: secondary_actor&.push_event_data,
|
||||||
user: user&.push_event_data,
|
user: user&.push_event_data,
|
||||||
created_at: created_at
|
created_at: created_at,
|
||||||
|
account_id: account_id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,11 @@ class Conversations::EventDataPresenter < SimpleDelegator
|
||||||
|
|
||||||
def push_data
|
def push_data
|
||||||
{
|
{
|
||||||
id: display_id,
|
|
||||||
additional_attributes: additional_attributes,
|
additional_attributes: additional_attributes,
|
||||||
|
id: display_id,
|
||||||
inbox_id: inbox_id,
|
inbox_id: inbox_id,
|
||||||
messages: push_messages,
|
messages: push_messages,
|
||||||
|
channel: inbox.try(:channel_type),
|
||||||
meta: push_meta,
|
meta: push_meta,
|
||||||
status: status,
|
status: status,
|
||||||
unread_count: unread_incoming_messages.count,
|
unread_count: unread_incoming_messages.count,
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
json.meta do
|
json.meta do
|
||||||
json.sender do
|
json.sender do
|
||||||
json.id conversation.contact.id
|
json.partial! 'api/v1/models/contact.json.jbuilder', resource: conversation.contact
|
||||||
json.name conversation.contact.name
|
|
||||||
json.thumbnail conversation.contact.avatar_url
|
|
||||||
json.channel conversation.inbox.try(:channel_type)
|
|
||||||
end
|
end
|
||||||
|
json.channel conversation.inbox.try(:channel_type)
|
||||||
json.assignee conversation.assignee
|
json.assignee conversation.assignee
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -312,6 +312,7 @@ RSpec.describe Conversation, type: :model do
|
||||||
inbox_id: conversation.inbox_id,
|
inbox_id: conversation.inbox_id,
|
||||||
status: conversation.status,
|
status: conversation.status,
|
||||||
timestamp: conversation.created_at.to_i,
|
timestamp: conversation.created_at.to_i,
|
||||||
|
channel: 'Channel::WebWidget',
|
||||||
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
||||||
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
||||||
unread_count: 0
|
unread_count: 0
|
||||||
|
|
|
@ -22,6 +22,7 @@ RSpec.describe Conversations::EventDataPresenter do
|
||||||
messages: [],
|
messages: [],
|
||||||
inbox_id: conversation.inbox_id,
|
inbox_id: conversation.inbox_id,
|
||||||
status: conversation.status,
|
status: conversation.status,
|
||||||
|
channel: conversation.inbox.channel_type,
|
||||||
timestamp: conversation.created_at.to_i,
|
timestamp: conversation.created_at.to_i,
|
||||||
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
||||||
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
||||||
|
|
Loading…
Reference in a new issue