Class: Jabber::Observable::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpp4r/observable/subscription.rb

Overview

Jabber::Observable::Subscriptions - convenience class to deal with Presence subscriptions

observable

points to a Jabber::Observable object

Instance Method Summary collapse

Constructor Details

#initialize(observable) ⇒ Subscriptions

Returns a new instance of Subscriptions.



13
14
15
16
# File 'lib/xmpp4r/observable/subscription.rb', line 13

def initialize(observable)
  @observable = observable
  @accept = true
end

Instance Method Details

#accept=(accept_status) ⇒ Object

Change whether or not subscriptions are automatically accepted.



51
52
53
# File 'lib/xmpp4r/observable/subscription.rb', line 51

def accept=(accept_status)
  @accept = accept_status
end

#accept?Boolean

Returns true if auto-accept subscriptions is enabled (default), false otherwise.

Returns:

  • (Boolean)


46
47
48
# File 'lib/xmpp4r/observable/subscription.rb', line 46

def accept?
  @accept
end

#add(*jids) ⇒ Object

Ask the users specified by jids for authorization (i.e., ask them to add you to their contact list), unless already in the contact list.

Because the authorization process depends on the other user accepting your request, results are notified to observers of :new_subscription.



23
24
25
26
27
28
# File 'lib/xmpp4r/observable/subscription.rb', line 23

def add(*jids)
  @observable.contacts(*jids).each do |contact|
    next if subscribed_to?(contact)
    contact.ask_for_authorization!
  end
end

#remove(*jids) ⇒ Object

Remove the jabber users specified by jids from the contact list.



31
32
33
34
35
# File 'lib/xmpp4r/observable/subscription.rb', line 31

def remove(*jids)
  @observable.contacts(*jids).each do |contact|
    contact.unsubscribe!
  end
end

#subscribed_to?(jid) ⇒ Boolean

Returns true if this Jabber account is subscribed to status updates for the jabber user jid, false otherwise.

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/xmpp4r/observable/subscription.rb', line 39

def subscribed_to?(jid)
  @observable.contacts(jid).each do |contact|
    return contact.subscribed?
  end
end