class Vines::Stanza::Message

Constants

FROM
VALID_TYPES

Public Instance Methods

process() click to toggle source
# 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)
        if Config.instance.max_offline_msgs > 0 && self[TYPE].match(/(chat|normal)/i)
          storage(to.domain).save_message(stream.user.jid.bare.to_s, to.to_s, @node.text)
        else
          raise StanzaErrors::ServiceUnavailable.new(self, 'cancel')
        end
      end
    else
      broadcast(recipients)
    end
  else
    self[FROM] = stream.user.jid.to_s
    route
  end
end