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

MESSAGE

Instance Attribute Summary

Attributes inherited from Vines::Stanza

#stream

Instance Method Summary collapse

Methods inherited from Vines::Stanza

#broadcast, from_node, #initialize, #local?, #method_missing, register, #route, #router, #send_unavailable, #storage, #unavailable

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
# 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 = (self[TO] || '').strip
    to = to.empty? ? stream.user.jid.bare : JID.new(to)
    recipients = router.connected_resources(to)
    if recipients.empty?
      if user = storage(to.domain).find_user(to)
        # TODO Implement offline messaging storage
        raise StanzaErrors::ServiceUnavailable.new(self, 'cancel')
      end
    else
      broadcast(recipients)
    end
  else
    self[FROM] = stream.user.jid.to_s
    route
  end
end