Sha256: f87ffc3bc66528a5baad0e7278aad09cf959222fdb1bf16ae83315a0cb1e6742

Contents?: true

Size: 1.5 KB

Versions: 25

Compression:

Stored size: 1.5 KB

Contents

# encoding: UTF-8

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

        def process
          stamp_from
          inbound? ? process_inbound : process_outbound
        end

        def process_outbound
          to = stamp_to
          stream.user.add_subscription_from(to)
          storage.save_user(stream.user)
          stream.update_user_streams(stream.user)
          local? ? process_inbound : route
          send_roster_push(to)
          send_known_presence(to)
        end

        def process_inbound
          to = stamp_to
          user = storage(to.domain).find_user(to)
          contact = user.contact(stream.user.jid) if user
          return unless contact && contact.can_subscribe?
          contact.subscribe_to
          storage(to.domain).save_user(user)
          stream.update_user_streams(user)
          broadcast_subscription_change(contact)
        end

        private

        # After approving a contact's subscription to this user's presence,
        # broadcast this user's most recent presence stanzas to the contact.
        def send_known_presence(to)
          stanzas = stream.available_resources(stream.user.jid).map do |stream|
            stream.last_broadcast_presence.clone.tap do |node|
              node['from'] = stream.user.jid.to_s
              node['id'] = Kit.uuid
            end
          end
          broadcast_to_available_resources(stanzas, to)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
diaspora-vines-0.2.0.develop.4 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.2.0.develop.3 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.2.0.develop.2 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.2.0.develop.1 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.28 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.27 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.26 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.25 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.24 lib/vines/stanza/presence/subscribed.rb
vines-0.4.10 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.22 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.21 lib/vines/stanza/presence/subscribed.rb
diaspora-vines-0.1.2 lib/vines/stanza/presence/subscribed.rb
vines-0.4.9 lib/vines/stanza/presence/subscribed.rb
vines-0.4.8 lib/vines/stanza/presence/subscribed.rb
vines-0.4.7 lib/vines/stanza/presence/subscribed.rb
vines-0.4.6 lib/vines/stanza/presence/subscribed.rb
vinesmod-0.4.5.2 lib/vines/stanza/presence/subscribed.rb
vinesmod-0.4.5 lib/vines/stanza/presence/subscribed.rb
vines-0.4.5 lib/vines/stanza/presence/subscribed.rb