Module: Puggernaut::Server::Shared

Included in:
Http, Websocket
Defined in:
lib/puggernaut/server/shared.rb

Instance Method Summary collapse

Instance Method Details

#gather_messages(channels, lasts, time) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/puggernaut/server/shared.rb', line 5

def gather_messages(channels, lasts, time)
  if time
    channels.inject([]) { |array, channel|
      array += Channel.all_messages_after_time(channel, Time.parse(time))
      array
    }.join("\n")
  elsif !lasts.empty?
    channels.inject([]) { |array, channel|
      array += Channel.all_messages_after_id(channel, lasts.shift)
      array
    }.join("\n")
  else
    ''
  end
end

#join_channels(channels, user_id) ⇒ Object



21
22
23
24
25
26
# File 'lib/puggernaut/server/shared.rb', line 21

def join_channels(channels, user_id)
  Channel.say channels.inject({}) { |hash, channel|
    hash[channel] = "!PUGJOIN#{user_id}"
    hash
  }, user_id
end

#leave_channel(channel) ⇒ Object



28
29
30
31
32
33
# File 'lib/puggernaut/server/shared.rb', line 28

def leave_channel(channel)
  Channel.say channel.channels.inject({}) { |hash, c|
    hash[c] = "!PUGLEAVE#{channel.user_id}"
    hash
  }, channel.user_id
end

#query_defaults(query) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/puggernaut/server/shared.rb', line 35

def query_defaults(query)
  [
    (query['channel'].dup rescue []),
    (query['join_leave'].dup[0] rescue nil),
    (query['last'].dup rescue []),
    (query['time'].dup[0] rescue nil),
    (query['user_id'].dup[0] rescue nil)
  ]
end