Class: Vines::Stanza::Message

Inherits:
Vines::Stanza show all
Defined in:
lib/vines/stanza/message.rb

Constant Summary collapse

VALID_TYPES =
%w[chat error groupchat headline normal].freeze

Constants inherited from Vines::Stanza

EMPTY, ROUTABLE_STANZAS

Instance Attribute Summary

Attributes inherited from Vines::Stanza

#stream

Instance Method Summary collapse

Methods inherited from Vines::Stanza

#broadcast, from_node, #initialize, #local?, #local_jid?, #method_missing, register, #route, #router, #send_unavailable, #storage, #to_pubsub_domain?, #unavailable, #validate_from, #validate_to

Constructor Details

This class inherits a constructor from Vines::Stanza

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vines::Stanza

Instance Method Details

#processObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vines/stanza/message.rb', line 17

def process
  unless self[TYPE].nil? || VALID_TYPES.include?(self[TYPE])
    raise StanzaErrors::BadRequest.new(self, 'modify')
  end

  if local?
    to = validate_to || stream.user.jid.bare
    recipients = stream.connected_resources(to)
    if recipients.empty?
      if user = storage(to.domain).find_user(to)
        msg_body = self.css('body').inner_text
        unless msg_body==""
          msg = {:from => stream.user.jid.to_s,:body=>msg_body,:to => to.bare.to_s}
          storage(to.domain).save_offline_message(msg)
        end                            
      end
    else
      broadcast(recipients)
    end
  else
    self[FROM] = stream.user.jid.to_s
    route
  end
end