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

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_recordObject

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

Returns:

  • (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

Returns:

  • (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_keyObject



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

#redisObject



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 send_message(content, attachment)
  messages.create(
    conversation: conversation,
    user: self
  )
end