Class: Xify::Input::RocketChat

Inherits:
Base::RocketChat show all
Defined in:
lib/xify/input/rocket_chat.rb

Instance Method Summary collapse

Methods inherited from Base::RocketChat

#initialize, #request

Constructor Details

This class inherits a constructor from Xify::Base::RocketChat

Instance Method Details

#updatesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xify/input/rocket_chat.rb', line 13

def updates
  

  EM.run do
    config = @config
    uri = URI.parse config['uri']
    meteor = Metybur.connect "wss://#{uri.host}:#{uri.port}/websocket"
    meteor. resume: @auth_data['authToken'] do
      meteor.subscribe 'stream-notify-user', "#{result[:id]}/rooms-changed", false
      messages = meteor.collection 'stream-notify-user'
      messages.on(:changed) do |id, attributes|
         event = attributes[:args].last
         room = event[:name]
         message = event[:lastMessage]

         next if message[:editedAt] || room != config['channel'][1..-1]

         author = message[:u][:name]
         text = message[:msg]
         time = message[:ts][:'$date']
         type = event[:t] == 'p' ? 'group' : 'channel'

         yield Xify::Event.new author, text, parent: "##{room}", parent_link: "#{config['uri']}/#{type}/#{room}", time: Time.at(time / 1000)
      end
    end
  end
end