Class: Vines::Stanza::Presence::Subscribed

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

Constant Summary

Constants inherited from Vines::Stanza::Presence

VALID_TYPES

Constants inherited from Vines::Stanza

MESSAGE

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?, #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



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

def process
  inbound? ? process_inbound : process_outbound
end

#process_inboundObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vines/stanza/presence/subscribed.rb', line 44

def process_inbound
  self['from'] = stream.user.jid.bare.to_s
  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)

  router.interested_resources(to).each do |recipient|
    recipient.write(@node)
    contact.send_roster_push(recipient)
  end
end

#process_outboundObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vines/stanza/presence/subscribed.rb', line 13

def process_outbound
  self['from'] = stream.user.jid.bare.to_s
  to = stamp_to
  local? ? process_inbound : route

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

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

  presences = router.available_resources(stream.user.jid).map do |c|
    c.last_broadcast_presence.clone.tap do |node|
      node['from'] = c.user.jid.to_s
      node['id'] = Kit.uuid
      node['to'] = to.to_s
    end
  end

  if local?
    router.available_resources(to).each do |recipient|
      presences.each {|el| recipient.write(el) }
    end
  else
    presences.each {|el| router.route(el) }
  end
end