Module: CustomerServiceIm::Concerns::Customer
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/customer_service_im/concerns/customer.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#as_redis_record ⇒ Object
example “User:1”.
- #join_conversation(conversation) ⇒ Object
- #offline! ⇒ Object
- #offline? ⇒ Boolean
- #online! ⇒ Object
- #online? ⇒ Boolean
- #online_customers_redis_key ⇒ Object
- #redis ⇒ Object
- #send_message(content, attachment) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 5 def self.included(klass) klass.class_eval do has_many :conversations, class_name: "CustomerServiceIm::Conversation" has_many :messages, class_name: "CustomerServiceIm::Message" end klass.extend ClassMethods end |
Instance Method Details
#as_redis_record ⇒ Object
example “User:1”
27 28 29 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 27 def as_redis_record "#{self.class.name}/#{self.id}" end |
#join_conversation(conversation) ⇒ Object
14 15 16 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 14 def join_conversation(conversation) conversation.update(user: self) end |
#offline! ⇒ Object
22 23 24 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 22 def offline! redis.sadd online_customers_redis_key, as_redis_record end |
#offline? ⇒ Boolean
35 36 37 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 35 def offline? !online? end |
#online! ⇒ Object
18 19 20 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 18 def online! redis.sadd online_customers_redis_key, as_redis_record end |
#online? ⇒ Boolean
31 32 33 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 31 def online? id.in? self.class.online_customers_ids end |
#online_customers_redis_key ⇒ Object
46 47 48 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 46 def online_customers_redis_key self.class.online_customers_redis_key end |
#redis ⇒ Object
50 51 52 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 50 def redis self.class.redis end |
#send_message(content, attachment) ⇒ Object
39 40 41 42 43 44 |
# File 'app/models/customer_service_im/concerns/customer.rb', line 39 def (content, ) .create( conversation: conversation, user: self ) end |