2019-11-30 13:39:55 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: inbox_members
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# inbox_id :integer not null
|
|
|
|
# user_id :integer not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2021-12-21 17:18:01 +00:00
|
|
|
# index_inbox_members_on_inbox_id (inbox_id)
|
|
|
|
# index_inbox_members_on_inbox_id_and_user_id (inbox_id,user_id) UNIQUE
|
2019-11-30 13:39:55 +00:00
|
|
|
#
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
class InboxMember < ApplicationRecord
|
|
|
|
validates :inbox_id, presence: true
|
|
|
|
validates :user_id, presence: true
|
2021-12-21 17:18:01 +00:00
|
|
|
validates :user_id, uniqueness: { scope: :inbox_id }
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :inbox
|
|
|
|
|
2019-08-19 08:19:57 +00:00
|
|
|
after_create :add_agent_to_round_robin
|
|
|
|
after_destroy :remove_agent_from_round_robin
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add_agent_to_round_robin
|
2020-07-07 18:44:07 +00:00
|
|
|
::RoundRobin::ManageService.new(inbox: inbox).add_agent_to_queue(user_id)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_agent_from_round_robin
|
2022-05-04 19:01:11 +00:00
|
|
|
::RoundRobin::ManageService.new(inbox: inbox).remove_agent_from_queue(user_id) if inbox.present?
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|