Class: CustomerServiceIm::Staff

Inherits:
ApplicationRecord show all
Defined in:
app/models/customer_service_im/staff.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.online_staffsObject



19
20
21
# File 'app/models/customer_service_im/staff.rb', line 19

def self.online_staffs
  where(id: online_staffs_ids)
end

Instance Method Details

#join_conversation(conversation) ⇒ Object



10
11
12
13
14
15
16
17
# File 'app/models/customer_service_im/staff.rb', line 10

def join_conversation(conversation)
  conversation.update(staff: self)

  conversation.messages.from_user.each do |message|
    message.update(staff: self)
    message.broadcast_to_conversation
  end
end

#offline!Object



27
28
29
# File 'app/models/customer_service_im/staff.rb', line 27

def offline!
  redis.srem self.class.online_staff_redis_key, as_redis_record
end

#offline?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/customer_service_im/staff.rb', line 35

def offline?
  !online?
end

#online!Object



23
24
25
# File 'app/models/customer_service_im/staff.rb', line 23

def online!
  redis.sadd self.class.online_staff_redis_key, as_redis_record
end

#online?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/customer_service_im/staff.rb', line 31

def online?
  id.in? self.class.online_staffs_ids
end