Sha256: 5a75bd302cf61205ead80f20445f4a4b0fc227534c49b85e59eb39134c27d4d7

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

# encoding: UTF-8

module Vines
  class Stanza
    class Presence
      class Subscribe < Presence
        register "/presence[@type='subscribe']"

        def process
          inbound? ? process_inbound : process_outbound
        end

        def process_outbound
          self['from'] = stream.user.jid.bare.to_s
          to = stamp_to

          stream.user.request_subscription(to)
          storage.save_user(stream.user)
          stream.update_user_streams(stream.user)

          local? ? process_inbound : route

          contact = stream.user.contact(to)
          stream.interested_resources(stream.user.jid).each do |recipient|
            contact.send_roster_push(recipient)
          end
        end

        def process_inbound
          self['from'] = stream.user.jid.bare.to_s
          to = stamp_to

          contact = storage(to.domain).find_user(to)
          if contact.nil?
            auto_reply_to_subscription_request(to, 'unsubscribed')
          elsif contact.subscribed_from?(stream.user.jid)
            auto_reply_to_subscription_request(to, 'subscribed')
          else
            recipients = stream.available_resources(to)
            if recipients.empty?
              # TODO store subscription request per RFC 6121 3.1.3 #4
            else
              recipients.each {|stream| stream.write(@node) }
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vines-0.3.2 lib/vines/stanza/presence/subscribe.rb
vines-0.3.1 lib/vines/stanza/presence/subscribe.rb
vines-0.3.0 lib/vines/stanza/presence/subscribe.rb