Compare commits

...
6 changed files with 36 additions and 9 deletions
+7 -3
View File
@@ -30,7 +30,7 @@ class ConversationFinder
def perform def perform
set_up set_up
mine_count, unassigned_count, all_count, = set_count_for_all_conversations mine_count, unassigned_count, all_count, unread_count = set_count_for_all_conversations
assigned_count = all_count - unassigned_count assigned_count = all_count - unassigned_count
filter_by_assignee_type filter_by_assignee_type
@@ -41,7 +41,8 @@ class ConversationFinder
mine_count: mine_count, mine_count: mine_count,
assigned_count: assigned_count, assigned_count: assigned_count,
unassigned_count: unassigned_count, unassigned_count: unassigned_count,
all_count: all_count all_count: all_count,
unread_count: unread_count
} }
} }
end end
@@ -147,7 +148,10 @@ class ConversationFinder
[ [
@conversations.assigned_to(current_user).count, @conversations.assigned_to(current_user).count,
@conversations.unassigned.count, @conversations.unassigned.count,
@conversations.count @conversations.count,
@conversations.joins(:messages)
.where('conversations.agent_last_seen_at IS NULL OR messages.created_at > conversations.agent_last_seen_at')
.distinct.count
] ]
end end
@@ -111,6 +111,7 @@ class ActionCableConnector extends BaseActionCableConnector {
} = data; } = data;
DashboardAudioNotificationHelper.onNewMessage(data); DashboardAudioNotificationHelper.onNewMessage(data);
this.app.$store.dispatch('addMessage', data); this.app.$store.dispatch('addMessage', data);
this.app.$store.dispatch('updateUnreadCount');
this.app.$store.dispatch('updateConversationLastActivity', { this.app.$store.dispatch('updateConversationLastActivity', {
lastActivityAt, lastActivityAt,
conversationId, conversationId,
@@ -289,6 +289,17 @@ const actions = {
} }
}, },
updateUnreadCount({ getters }) {
const { installationName } = window.chatwootConfig;
const unreadCount = getters.getUnreadConversationsCount;
if (unreadCount === 0) {
document.title = installationName;
} else {
document.title = `${installationName} (${getters.getUnreadConversationsCount})`;
}
},
updateMessage({ commit }, message) { updateMessage({ commit }, message) {
commit(types.ADD_MESSAGE, message); commit(types.ADD_MESSAGE, message);
}, },
@@ -10,6 +10,15 @@ export const getSelectedChatConversation = ({
}) => }) =>
allConversations.filter(conversation => conversation.id === selectedChatId); allConversations.filter(conversation => conversation.id === selectedChatId);
export const getUnreadCountForChat = chat => {
return chat.messages.filter(
chatMessage =>
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&
chatMessage.message_type === 0 &&
chatMessage.private !== true
).length;
};
const sortComparator = { const sortComparator = {
latest: (a, b) => b.last_activity_at - a.last_activity_at, latest: (a, b) => b.last_activity_at - a.last_activity_at,
sort_on_created_at: (a, b) => a.created_at - b.created_at, sort_on_created_at: (a, b) => a.created_at - b.created_at,
@@ -107,15 +116,15 @@ const getters = {
? false ? false
: chat.allMessagesLoaded; : chat.allMessagesLoaded;
}, },
getUnreadConversationsCount({ allConversations }) {
return allConversations.filter(chat => {
return getUnreadCountForChat(chat) > 0;
}).length;
},
getUnreadCount(_state) { getUnreadCount(_state) {
const [chat] = getSelectedChatConversation(_state); const [chat] = getSelectedChatConversation(_state);
if (!chat) return []; if (!chat) return [];
return chat.messages.filter( return getUnreadCountForChat(chat);
chatMessage =>
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&
chatMessage.message_type === 0 &&
chatMessage.private !== true
).length;
}, },
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter, getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
getChatSortFilter: ({ chatSortFilter }) => chatSortFilter, getChatSortFilter: ({ chatSortFilter }) => chatSortFilter,
@@ -4,6 +4,7 @@ json.data do
json.assigned_count @conversations_count[:assigned_count] json.assigned_count @conversations_count[:assigned_count]
json.unassigned_count @conversations_count[:unassigned_count] json.unassigned_count @conversations_count[:unassigned_count]
json.all_count @conversations_count[:all_count] json.all_count @conversations_count[:all_count]
json.unread_count @conversations_count[:unread_count]
end end
json.payload do json.payload do
json.array! @conversations do |conversation| json.array! @conversations do |conversation|
+1
View File
@@ -32,6 +32,7 @@
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
<script> <script>
window.chatwootConfig = { window.chatwootConfig = {
installationName: '<%= @global_config['INSTALLATION_NAME'] %>',
hostURL: '<%= ENV.fetch('FRONTEND_URL', '') %>', hostURL: '<%= ENV.fetch('FRONTEND_URL', '') %>',
helpCenterURL: '<%= ENV.fetch('HELPCENTER_URL', '') %>', helpCenterURL: '<%= ENV.fetch('HELPCENTER_URL', '') %>',
fbAppId: '<%= ENV.fetch('FB_APP_ID', nil) %>', fbAppId: '<%= ENV.fetch('FB_APP_ID', nil) %>',