public final class RosterManager extends Object
Contacts are often organized in groups, which may contain nested groups by themselves. This manager takes care for sorting the the contacts in the right group and also creates the group hierarchy for nested groups.
Nested groups are determined by a delimiter, which must be set prior to requesting the roster.
By adding a RosterListener, you can listen for roster updates (aka roster pushes) in order to update the view.
| Constructor and Description |
|---|
RosterManager(XmppSession xmppSession) |
| Modifier and Type | Method and Description |
|---|---|
void |
addContact(Contact contact,
boolean requestSubscription,
String status)
Adds a contact to the roster and optionally also sends a subscription request to it.
|
void |
addRosterListener(RosterListener rosterListener)
Adds a roster listener, which will get notified, whenever the roster changes.
|
Contact |
getContact(Jid jid)
Gets a contact by its JID.
|
Collection<ContactGroup> |
getContactGroups()
Gets the contact groups.
|
Collection<Contact> |
getContacts()
Gets the contacts.
|
String |
getGroupDelimiter()
Gets the group delimiter.
|
Collection<Contact> |
getUnaffiliatedContacts()
Gets the contacts, which are not affiliated to any group.
|
boolean |
isRetrieveRosterOnLogin()
Controls, whether the roster is automatically retrieved as soon as the user has logged in.
|
void |
removeContact(Jid jid)
Removes a contact from the roster.
|
void |
removeContactGroup(ContactGroup contactGroup)
Removes a contact group.
|
void |
removeRosterListener(RosterListener rosterListener)
Removes a previously added roster listener.
|
void |
renameContactGroup(ContactGroup contactGroup,
String name)
Renames a contact group.
|
void |
requestRoster()
Requests the roster from the server.
|
void |
setGroupDelimiter(String groupDelimiter)
Sets the group delimiter.
|
void |
setRetrieveRosterOnLogin(boolean retrieveRosterOnLogin)
Controls, whether the roster is automatically retrieved as soon as the user has logged in.
|
void |
updateContact(Contact contact)
Updates a contact in the roster.
|
public RosterManager(XmppSession xmppSession)
public Collection<Contact> getContacts()
public Contact getContact(Jid jid)
jid - The JID.public Collection<ContactGroup> getContactGroups()
public Collection<Contact> getUnaffiliatedContacts()
public void addRosterListener(RosterListener rosterListener)
rosterListener - The roster listener.removeRosterListener(RosterListener)public void removeRosterListener(RosterListener rosterListener)
rosterListener - The roster listener.addRosterListener(RosterListener)public boolean isRetrieveRosterOnLogin()
setRetrieveRosterOnLogin(boolean)public void setRetrieveRosterOnLogin(boolean retrieveRosterOnLogin)
2.2. Retrieving the Roster on Login
Upon authenticating with a server and binding a resource (thus becoming a connected resource as defined in [XMPP-CORE]), a client SHOULD request the roster before sending initial presence (however, because receiving the roster is not necessarily desirable for all resources, e.g., a connection with limited bandwidth, the client's request for the roster is not mandatory).
retrieveRosterOnLogin - True, if the roster is automatically retrieved after login.public void requestRoster()
RosterListener are notified.
That means, you should first register a RosterListener prior to calling this method.public void addContact(Contact contact, boolean requestSubscription, String status) throws XmppException
contact - The contact.requestSubscription - If true, the contact is also sent a subscription request.status - The optional status text, which is sent together with a subscription request. May be null.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic void updateContact(Contact contact) throws XmppException
contact - The contact to update.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic void removeContact(Jid jid) throws XmppException
jid - The contact's JID.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic void renameContactGroup(ContactGroup contactGroup, String name) throws XmppException
contactGroup - The contact group.name - The new name.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic void removeContactGroup(ContactGroup contactGroup) throws XmppException
contactGroup - The contact group.StanzaException - If the entity returned a stanza error.NoResponseException - If the entity did not respond.XmppExceptionpublic String getGroupDelimiter()
setGroupDelimiter(String)public void setGroupDelimiter(String groupDelimiter)
If this is set to a non-null value, contact groups are split by the specified delimiter in order to build a nested hierarchy of groups.
groupDelimiter - The group delimiter.Copyright © 2014 XMPP.rocks. All rights reserved.