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
This commit is contained in:
@@ -35,37 +35,38 @@ class Account < ApplicationRecord
|
||||
has_many :account_users, dependent: :destroy_async
|
||||
has_many :agent_bot_inboxes, dependent: :destroy_async
|
||||
has_many :agent_bots, dependent: :destroy_async
|
||||
has_many :csat_survey_responses, dependent: :destroy_async
|
||||
has_many :data_imports, dependent: :destroy_async
|
||||
has_many :users, through: :account_users
|
||||
has_many :inboxes, dependent: :destroy_async
|
||||
has_many :notes, dependent: :destroy_async
|
||||
has_many :api_channels, dependent: :destroy_async, class_name: '::Channel::Api'
|
||||
has_many :campaigns, dependent: :destroy_async
|
||||
has_many :conversations, dependent: :destroy_async
|
||||
has_many :messages, dependent: :destroy_async
|
||||
has_many :canned_responses, dependent: :destroy_async
|
||||
has_many :contacts, dependent: :destroy_async
|
||||
has_many :conversations, dependent: :destroy_async
|
||||
has_many :csat_survey_responses, dependent: :destroy_async
|
||||
has_many :custom_attribute_definitions, dependent: :destroy_async
|
||||
has_many :custom_filters, dependent: :destroy_async
|
||||
has_many :data_imports, dependent: :destroy_async
|
||||
has_many :email_channels, dependent: :destroy_async, class_name: '::Channel::Email'
|
||||
has_many :facebook_pages, dependent: :destroy_async, class_name: '::Channel::FacebookPage'
|
||||
has_many :hooks, dependent: :destroy_async, class_name: 'Integrations::Hook'
|
||||
has_many :inboxes, dependent: :destroy_async
|
||||
has_many :kbase_articles, dependent: :destroy_async, class_name: '::Kbase::Article'
|
||||
has_many :kbase_categories, dependent: :destroy_async, class_name: '::Kbase::Category'
|
||||
has_many :kbase_portals, dependent: :destroy_async, class_name: '::Kbase::Portal'
|
||||
has_many :labels, dependent: :destroy_async
|
||||
has_many :line_channels, dependent: :destroy_async, class_name: '::Channel::Line'
|
||||
has_many :mentions, dependent: :destroy_async
|
||||
has_many :messages, dependent: :destroy_async
|
||||
has_many :notes, dependent: :destroy_async
|
||||
has_many :notification_settings, dependent: :destroy_async
|
||||
has_many :teams, dependent: :destroy_async
|
||||
has_many :telegram_bots, dependent: :destroy_async
|
||||
has_many :telegram_channels, dependent: :destroy_async, class_name: '::Channel::Telegram'
|
||||
has_many :twilio_sms, dependent: :destroy_async, class_name: '::Channel::TwilioSms'
|
||||
has_many :twitter_profiles, dependent: :destroy_async, class_name: '::Channel::TwitterProfile'
|
||||
has_many :users, through: :account_users
|
||||
has_many :web_widgets, dependent: :destroy_async, class_name: '::Channel::WebWidget'
|
||||
has_many :email_channels, dependent: :destroy_async, class_name: '::Channel::Email'
|
||||
has_many :api_channels, dependent: :destroy_async, class_name: '::Channel::Api'
|
||||
has_many :line_channels, dependent: :destroy_async, class_name: '::Channel::Line'
|
||||
has_many :telegram_channels, dependent: :destroy_async, class_name: '::Channel::Telegram'
|
||||
has_many :whatsapp_channels, dependent: :destroy_async, class_name: '::Channel::Whatsapp'
|
||||
has_many :canned_responses, dependent: :destroy_async
|
||||
has_many :webhooks, dependent: :destroy_async
|
||||
has_many :labels, dependent: :destroy_async
|
||||
has_many :notification_settings, dependent: :destroy_async
|
||||
has_many :hooks, dependent: :destroy_async, class_name: 'Integrations::Hook'
|
||||
has_many :whatsapp_channels, dependent: :destroy_async, class_name: '::Channel::Whatsapp'
|
||||
has_many :working_hours, dependent: :destroy_async
|
||||
has_many :kbase_portals, dependent: :destroy_async, class_name: '::Kbase::Portal'
|
||||
has_many :kbase_categories, dependent: :destroy_async, class_name: '::Kbase::Category'
|
||||
has_many :kbase_articles, dependent: :destroy_async, class_name: '::Kbase::Article'
|
||||
has_many :teams, dependent: :destroy_async
|
||||
has_many :custom_filters, dependent: :destroy_async
|
||||
has_many :custom_attribute_definitions, dependent: :destroy_async
|
||||
|
||||
has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING)
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ class Conversation < ApplicationRecord
|
||||
belongs_to :team, optional: true
|
||||
belongs_to :campaign, optional: true
|
||||
|
||||
has_many :mentions, dependent: :destroy_async
|
||||
has_many :messages, dependent: :destroy_async, autosave: true
|
||||
has_one :csat_survey_response, dependent: :destroy_async
|
||||
has_many :notifications, as: :primary_actor, dependent: :destroy
|
||||
|
||||
50
app/models/mention.rb
Normal file
50
app/models/mention.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: mentions
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# mentioned_at :datetime not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
# conversation_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_mentions_on_account_id (account_id)
|
||||
# index_mentions_on_conversation_id (conversation_id)
|
||||
# index_mentions_on_user_id (user_id)
|
||||
# index_mentions_on_user_id_and_conversation_id (user_id,conversation_id) UNIQUE
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (conversation_id => conversations.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
class Mention < ApplicationRecord
|
||||
before_validation :ensure_account_id
|
||||
validates :mentioned_at, presence: true
|
||||
validates :account_id, presence: true
|
||||
validates :conversation_id, presence: true
|
||||
validates :user_id, presence: true
|
||||
validates :user, uniqueness: { scope: :conversation }
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :conversation
|
||||
belongs_to :user
|
||||
|
||||
after_commit :notify_mentioned_user
|
||||
|
||||
scope :latest, -> { order(mentioned_at: :desc) }
|
||||
|
||||
private
|
||||
|
||||
def ensure_account_id
|
||||
self.account_id = conversation&.account_id
|
||||
end
|
||||
|
||||
def notify_mentioned_user
|
||||
Rails.configuration.dispatcher.dispatch(CONVERSATION_MENTIONED, Time.zone.now, user: user, conversation: conversation)
|
||||
end
|
||||
end
|
||||
@@ -80,13 +80,14 @@ class User < ApplicationRecord
|
||||
has_many :messages, as: :sender
|
||||
has_many :invitees, through: :account_users, class_name: 'User', foreign_key: 'inviter_id', source: :inviter, dependent: :nullify
|
||||
|
||||
has_many :notifications, dependent: :destroy_async
|
||||
has_many :custom_filters, dependent: :destroy_async
|
||||
has_many :mentions, dependent: :destroy_async
|
||||
has_many :notes, dependent: :nullify
|
||||
has_many :notification_settings, dependent: :destroy_async
|
||||
has_many :notification_subscriptions, dependent: :destroy_async
|
||||
has_many :notifications, dependent: :destroy_async
|
||||
has_many :team_members, dependent: :destroy_async
|
||||
has_many :teams, through: :team_members
|
||||
has_many :notes, dependent: :nullify
|
||||
has_many :custom_filters, dependent: :destroy_async
|
||||
|
||||
before_validation :set_password_and_uid, on: :create
|
||||
|
||||
|
||||
Reference in New Issue
Block a user