Module: Hector::Concerns::Presence

Included in:
Session
Defined in:
lib/hector/concerns/presence.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
8
# File 'lib/hector/concerns/presence.rb', line 4

def self.included(klass)
  klass.class_eval do
    attr_reader :created_at, :updated_at
  end
end

Instance Method Details

#channelsObject



10
11
12
# File 'lib/hector/concerns/presence.rb', line 10

def channels
  Channel.find_all_for_session(self)
end

#destroy_presenceObject



20
21
22
23
# File 'lib/hector/concerns/presence.rb', line 20

def destroy_presence
  deliver_quit_message
  leave_all_channels
end

#initialize_presenceObject



14
15
16
17
18
# File 'lib/hector/concerns/presence.rb', line 14

def initialize_presence
  @created_at = Time.now
  @updated_at = Time.now
  deliver_welcome_message
end

#peer_sessionsObject



29
30
31
# File 'lib/hector/concerns/presence.rb', line 29

def peer_sessions
  [self, *channels.map { |channel| channel.sessions }.flatten].uniq
end

#seconds_idleObject



25
26
27
# File 'lib/hector/concerns/presence.rb', line 25

def seconds_idle
  Time.now - updated_at
end

#touch_presenceObject



33
34
35
# File 'lib/hector/concerns/presence.rb', line 33

def touch_presence
  @updated_at = Time.now
end