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
|
|
|
|
#
|
|
|
|
# index_inbox_members_on_inbox_id (inbox_id)
|
|
|
|
#
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
class InboxMember < ApplicationRecord
|
|
|
|
validates :inbox_id, presence: true
|
|
|
|
validates :user_id, presence: true
|
|
|
|
|
|
|
|
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
|
2019-10-20 08:47:26 +00:00
|
|
|
Redis::Alfred.lpush(round_robin_key, user_id)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_agent_from_round_robin
|
2019-10-20 08:47:26 +00:00
|
|
|
Redis::Alfred.lrem(round_robin_key, user_id)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def round_robin_key
|
2019-10-20 08:47:26 +00:00
|
|
|
format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: inbox_id)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|