From 2be71e73dc0076f21d58b6bfd6057fbd51810522 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Wed, 8 Dec 2021 21:50:14 -0800 Subject: [PATCH] feat: Add a view for mentions (#3505) - Added a new table mentions for saving user mentions - Added a filter conversation_type in the API - Added a view to see the mentions --- app/finders/conversation_finder.rb | 13 +++- .../dashboard/api/inbox/conversation.js | 14 ++++- .../dashboard/components/ChatList.vue | 14 +++++ .../config/sidebarItems/conversations.js | 9 +++ .../components/specs/SidemenuIcon.spec.js | 4 +- .../widgets/conversation/ConversationCard.vue | 5 ++ .../conversation/specs/MoreActions.spec.js | 3 +- app/javascript/dashboard/helper/URLHelper.js | 18 +++--- .../dashboard/helper/actionCable.js | 5 ++ .../dashboard/i18n/locale/en/chatlist.json | 1 + .../dashboard/i18n/locale/en/settings.json | 1 + .../conversation/ConversationView.vue | 5 ++ .../conversation/conversation.routes.js | 37 +++++++++--- .../store/modules/conversations/actions.js | 55 ++++++----------- .../conversations/helpers/actionHelpers.js | 46 +++++++++++++++ .../helpers/specs/actionHelpers.spec.js | 12 ++++ .../specs/conversations/actions.spec.js | 59 ++++++++++++++++++- .../FluentIcon/dashboard-icons.json | 18 +++--- app/jobs/conversations/user_mention_job.rb | 24 ++++++++ app/listeners/action_cable_listener.rb | 7 +++ app/listeners/notification_listener.rb | 5 +- app/models/account.rb | 45 +++++++------- app/models/conversation.rb | 1 + app/models/mention.rb | 50 ++++++++++++++++ app/models/user.rb | 7 ++- db/migrate/20211201224513_create_mentions.rb | 13 ++++ db/schema.rb | 15 +++++ lib/events/types.rb | 1 + 28 files changed, 389 insertions(+), 98 deletions(-) create mode 100644 app/javascript/dashboard/store/modules/conversations/helpers/actionHelpers.js create mode 100644 app/javascript/dashboard/store/modules/conversations/helpers/specs/actionHelpers.spec.js create mode 100644 app/jobs/conversations/user_mention_job.rb create mode 100644 app/models/mention.rb create mode 100644 db/migrate/20211201224513_create_mentions.rb diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index f2641dde0..3409a2450 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -70,7 +70,12 @@ class ConversationFinder end def find_all_conversations - @conversations = current_account.conversations.where(inbox_id: @inbox_ids) + if params[:conversation_type] == 'mention' + conversation_ids = current_account.mentions.where(user: current_user).pluck(:conversation_id) + @conversations = current_account.conversations.where(id: conversation_ids) + else + @conversations = current_account.conversations.where(inbox_id: @inbox_ids) + end end def filter_by_assignee_type @@ -123,6 +128,10 @@ class ConversationFinder @conversations = @conversations.includes( :taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team, :contact_inbox ) - @conversations.latest.page(current_page) + if params[:conversation_type] == 'mention' + @conversations.page(current_page) + else + @conversations.latest.page(current_page) + end end end diff --git a/app/javascript/dashboard/api/inbox/conversation.js b/app/javascript/dashboard/api/inbox/conversation.js index 8fca2b83c..9f6b8baf1 100644 --- a/app/javascript/dashboard/api/inbox/conversation.js +++ b/app/javascript/dashboard/api/inbox/conversation.js @@ -6,7 +6,15 @@ class ConversationApi extends ApiClient { super('conversations', { accountScoped: true }); } - get({ inboxId, status, assigneeType, page, labels, teamId }) { + get({ + inboxId, + status, + assigneeType, + page, + labels, + teamId, + conversationType, + }) { return axios.get(this.url, { params: { inbox_id: inboxId, @@ -15,6 +23,7 @@ class ConversationApi extends ApiClient { assignee_type: assigneeType, page, labels, + conversation_type: conversationType, }, }); } @@ -74,7 +83,7 @@ class ConversationApi extends ApiClient { return axios.post(`${this.url}/${conversationId}/unmute`); } - meta({ inboxId, status, assigneeType, labels, teamId }) { + meta({ inboxId, status, assigneeType, labels, teamId, conversationType }) { return axios.get(`${this.url}/meta`, { params: { inbox_id: inboxId, @@ -82,6 +91,7 @@ class ConversationApi extends ApiClient { assignee_type: assigneeType, labels, team_id: teamId, + conversation_type: conversationType, }, }); } diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index 1517105df..2abffb1c8 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -51,6 +51,7 @@ l