Module: CustomerServiceIm::Concerns::Customer::ClassMethods

Defined in:
app/models/customer_service_im/concerns/customer.rb

Instance Method Summary collapse

Instance Method Details

#find_or_create_mp_user(open_id) ⇒ Object



75
76
77
78
79
80
81
# File 'app/models/customer_service_im/concerns/customer.rb', line 75

def find_or_create_mp_user(open_id)
  return if open_id.blank?

  User.create_with(
    email: "#{SecureRandom.uuid}@mp.com",
  ).find_or_create_by(open_id: open_id)
end

#online_customer_list_in_redisObject



71
72
73
# File 'app/models/customer_service_im/concerns/customer.rb', line 71

def online_customer_list_in_redis
  redis.smembers online_customers_redis_key
end

#online_customersObject



55
56
57
# File 'app/models/customer_service_im/concerns/customer.rb', line 55

def online_customers
  where(id: online_customers_ids)
end

#online_customers_idsObject



59
60
61
# File 'app/models/customer_service_im/concerns/customer.rb', line 59

def online_customers_ids
  online_customer_list_in_redis&.map{|str| str.split("/").second.to_i}
end

#online_customers_redis_keyObject



67
68
69
# File 'app/models/customer_service_im/concerns/customer.rb', line 67

def online_customers_redis_key
  "#{CustomerServiceIm.appid}_online_customers"
end

#redisObject



63
64
65
# File 'app/models/customer_service_im/concerns/customer.rb', line 63

def redis
  @redis ||= Redis.current
end