2022-11-16 23:43:55 +00:00
|
|
|
const getLastNonActivityMessage = (messageInStore, messageFromAPI) => {
|
|
|
|
// If both API value and store value for last non activity message
|
|
|
|
// are available, then return the latest one.
|
|
|
|
if (messageInStore && messageFromAPI) {
|
|
|
|
if (messageInStore.created_at >= messageFromAPI.created_at) {
|
|
|
|
return messageInStore;
|
|
|
|
}
|
|
|
|
return messageFromAPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, return whichever is available
|
|
|
|
return messageInStore || messageFromAPI;
|
|
|
|
};
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
methods: {
|
|
|
|
lastMessage(m) {
|
2022-11-16 23:43:55 +00:00
|
|
|
let lastMessageIncludingActivity = m.messages.last();
|
|
|
|
|
|
|
|
const nonActivityMessages = m.messages.filter(
|
|
|
|
message => message.message_type !== 2
|
|
|
|
);
|
|
|
|
let lastNonActivityMessageInStore = nonActivityMessages.last();
|
|
|
|
let lastNonActivityMessageFromAPI = m.last_non_activity_message;
|
|
|
|
|
|
|
|
// If API value and store value for last non activity message
|
|
|
|
// is empty, then return the last activity message
|
|
|
|
if (!lastNonActivityMessageInStore && !lastNonActivityMessageFromAPI) {
|
|
|
|
return lastMessageIncludingActivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getLastNonActivityMessage(
|
|
|
|
lastNonActivityMessageInStore,
|
|
|
|
lastNonActivityMessageFromAPI
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2022-04-20 10:33:12 +00:00
|
|
|
hasUserReadMessage(createdAt, contactLastSeen) {
|
|
|
|
return !(contactLastSeen - createdAt < 0);
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
readMessages(m) {
|
2019-08-21 07:29:56 +00:00
|
|
|
return m.messages.filter(
|
|
|
|
chat => chat.created_at * 1000 <= m.agent_last_seen_at * 1000
|
2019-08-14 09:48:44 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
unReadMessages(m) {
|
2019-08-21 07:29:56 +00:00
|
|
|
return m.messages.filter(
|
|
|
|
chat => chat.created_at * 1000 > m.agent_last_seen_at * 1000
|
2019-08-14 09:48:44 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|