Class: Vines::Stanza::Presence::Subscribe

Inherits:
Vines::Stanza::Presence show all
Defined in:
lib/vines/stanza/presence/subscribe.rb

Constant Summary

Constants inherited from Vines::Stanza::Presence

VALID_TYPES

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::Presence

#inbound?, #inbound_broadcast_presence, #outbound?, #outbound_broadcast_presence

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



9
10
11
12
# File 'lib/vines/stanza/presence/subscribe.rb', line 9

def process
  stamp_from
  inbound? ? process_inbound : process_outbound
end

#process_inboundObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vines/stanza/presence/subscribe.rb', line 23

def process_inbound
  to = stamp_to
  follower = storage(to.domain).find_user(to)
  if follower.nil?
    auto_reply_to_subscription_request(to, 'unsubscribed')
  elsif follower.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
      broadcast_to_available_resources([@node], to)
    end
  end
end

#process_outboundObject



14
15
16
17
18
19
20
21
# File 'lib/vines/stanza/presence/subscribe.rb', line 14

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