Class: Jabber::Roster::RosterItem

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber4r/roster.rb

Overview

The RosterItem class embodies another Jabber user’s status (from the local user’s perspective). RosterItems contain Jabber::Roster::RosterItem::Resource objects for each resource location a foreign user is accessing through.

Defined Under Namespace

Classes: Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(roster, jid, subscription, name, group = nil) ⇒ RosterItem

Constructs a RosterItem

roster
Jabber::Roster

The roster instance

subscription
String

The subscription type

name
String

The (nick)name

group
String=nil

The group this account belongs to



64
65
66
67
68
69
70
71
# File 'lib/jabber4r/roster.rb', line 64

def initialize(roster, jid, subscription, name, group=nil)
  @jid = jid
  @subscription = subscription
  @name = name
  @group = group if group
  @resources = {}
  @roster = roster
end

Instance Attribute Details

#groupObject

The group name for this account



54
55
56
# File 'lib/jabber4r/roster.rb', line 54

def group
  @group
end

#jidObject

The Jabber ID (Jabber::JID)



45
46
47
# File 'lib/jabber4r/roster.rb', line 45

def jid
  @jid
end

#nameObject

The (nick)name of this account



51
52
53
# File 'lib/jabber4r/roster.rb', line 51

def name
  @name
end

#rosterObject (readonly)

The Jabber::Roster instance



42
43
44
# File 'lib/jabber4r/roster.rb', line 42

def roster
  @roster
end

#subscriptionObject

The subscription type



48
49
50
# File 'lib/jabber4r/roster.rb', line 48

def subscription
  @subscription
end

Instance Method Details

#[](resourceName) ⇒ Object

Retrieves a resource object

resourceName
String

The name of the resource

return
Jabber::Roster:RosterItem::Resource

The Resource instance



180
181
182
# File 'lib/jabber4r/roster.rb', line 180

def [](resourceName)
  return @resources[resourceName]
end

#add(resourceName, show, status) ⇒ Object

Adds a new resource to the Roster item and notifies listeners

resourceName
String

The name of the resource

show
String

How the resource is to be viewed

status
String

The status message

return
Jabber::Roster:RosterItem::Resource

The new Resource instance



155
156
157
158
159
160
# File 'lib/jabber4r/roster.rb', line 155

def add(resourceName, show, status)
  resource = Resource.new(self, resourceName, show, status)
  @resources[resourceName] = resource
  @roster.notify_listeners(RESOURCE_ADDED, resource)
  resource
end

#delete(resourceName) ⇒ Object

Deletes a resource from this roster item and notifies listeners

resourceName
String

The name of the resource

return
Jabber::Roster:RosterItem::Resource

The deleted Resource



168
169
170
171
172
# File 'lib/jabber4r/roster.rb', line 168

def delete(resourceName)
  resource = @resources.delete(resourceName)
  @roster.notify_listeners(RESOURCE_DELETED, resource) if resource
  resource
end

#each_resourceObject

Iterates over the list of available resources

yield

|Jabber::Roster:RosterItem::Resource| The resource instance



189
190
191
# File 'lib/jabber4r/roster.rb', line 189

def each_resource
  @resources.each_value {|resource| yield resource}
end

#get_vcardObject

Retrieves the VCard for this (RosterItem) account. This method blocks until the the vcard is returned.

return
Jabber::VCard

The VCard object for this account



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/jabber4r/roster.rb', line 131

def get_vcard
  ct = Thread.current
  queryID = @roster.session.id
  result = nil
  @roster.session.connection.send(Jabber::Protocol::Iq.gen_vcard(self, queryID, jid)) { |je|
      if je.element_tag == "iq" and je.attr_type=="result" and je.attr_id == queryID
        je.consume_element
        result = Jabber::VCard.from_element(je.VCARD)
        ct.wakeup
      else
      end
  }
  Thread.stop
  return result
end

#to_sObject

Dumps the roster item

return
String

The roster item dumped as a String



197
198
199
# File 'lib/jabber4r/roster.rb', line 197

def to_s
  "ITEM:#{@jid.to_s} SUBSCRIPTION:#{@subscription} NAME:#{@name} GROUP:#{@group}"
end