Sha256: 661f8c32d58607c9594a6077da00cc03dbb3e1b9ad613f71f12450e86845f110

Contents?: true

Size: 812 Bytes

Versions: 7

Compression:

Stored size: 812 Bytes

Contents

module Cubism::Presence
  extend ActiveSupport::Concern

  included do
    kredis_hash :present_users, after_change: :stream_presence
    kredis_set :cubicle_element_ids
    kredis_hash :excluded_user_id_for_element_id
  end

  def stream_presence
    Cubism::Broadcaster.new(resource: self).broadcast
  end

  def present_users_for_scope(scope = "")
    present_users[scope].present? ? Marshal.load(present_users[scope]) : Set.new
  end

  def set_present_users_for_scope(user_ids, scope = "")
    present_users[scope] = Marshal.dump(Set.new(user_ids))
  end

  def present_users_for_element_id_and_scope(element_id, scope = "")
    users = Cubism.user_class.find(present_users_for_scope(scope).to_a)
    users.reject! { |user| user.id == excluded_user_id_for_element_id[element_id].to_i }

    users
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cubism-0.2.0 app/models/concerns/cubism/presence.rb
cubism-0.1.1 app/models/concerns/cubism/presence.rb
cubism-0.1.0 app/models/concerns/cubism/presence.rb
cubism-0.1.0.rc2 app/models/concerns/cubism/presence.rb
cubism-0.1.0.rc1 app/models/concerns/cubism/presence.rb
cubism-0.1.0.pre13 app/models/concerns/cubism/presence.rb
cubism-0.1.0.pre12 app/models/concerns/cubism/presence.rb