Chatwoot/app/models/inbox_member.rb
Sojan Jose 0fc0dc1683
Chore: Refactor round robin logic (#1015)
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
2020-07-08 00:14:07 +05:30

35 lines
837 B
Ruby

# == 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
#
# index_inbox_members_on_inbox_id (inbox_id)
#
class InboxMember < ApplicationRecord
validates :inbox_id, presence: true
validates :user_id, presence: true
belongs_to :user
belongs_to :inbox
after_create :add_agent_to_round_robin
after_destroy :remove_agent_from_round_robin
private
def add_agent_to_round_robin
::RoundRobin::ManageService.new(inbox: inbox).add_agent_to_queue(user_id)
end
def remove_agent_from_round_robin
::RoundRobin::ManageService.new(inbox: inbox).remove_agent_from_queue(user_id)
end
end