public class Roster extends Manager
Others users may attempt to subscribe to this user using a subscription request. Three modes are supported for handling these requests:
accept_all
-- accept all subscription requests.reject_all
-- reject all subscription requests.manual
-- manually process all subscription requests.getInstanceFor(XMPPConnection)
Modifier and Type | Class and Description |
---|---|
static class |
Roster.SubscriptionMode
An enumeration for the subscription mode options.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addRosterListener(RosterListener rosterListener)
Adds a listener to this roster.
|
boolean |
addRosterLoadedListener(RosterLoadedListener rosterLoadedListener)
Add a roster loaded listener.
|
boolean |
contains(String user)
Returns true if the specified XMPP address is an entry in the roster.
|
void |
createEntry(String user,
String name,
String[] groups)
Creates a new roster entry and presence subscription.
|
RosterGroup |
createGroup(String name)
Creates a new group.
|
List<Presence> |
getAllPresences(String bareJid)
Returns a List of Presence objects for all of a user's current presences if no presence information is available,
such as when you are not subscribed to the user's presence updates.
|
List<Presence> |
getAvailablePresences(String bareJid)
Returns a List of all available Presence Objects for the given bare JID.
|
static Roster.SubscriptionMode |
getDefaultSubscriptionMode()
Returns the default subscription processing mode to use when a new Roster is created.
|
Set<RosterEntry> |
getEntries()
Returns a set of all entries in the roster, including entries
that don't belong to any groups.
|
void |
getEntriesAndAddListener(RosterListener rosterListener,
RosterEntries rosterEntries)
Add a roster listener and invoke the roster entries with all entries of the roster.
|
RosterEntry |
getEntry(String user)
Returns the roster entry associated with the given XMPP address or
null if the user is not an entry in the roster.
|
int |
getEntryCount()
Returns a count of the entries in the roster.
|
RosterGroup |
getGroup(String name)
Returns the roster group with the specified name, or null if the
group doesn't exist.
|
int |
getGroupCount()
Returns the number of the groups in the roster.
|
Collection<RosterGroup> |
getGroups()
Returns an unmodifiable collections of all the roster groups.
|
static Roster |
getInstanceFor(XMPPConnection connection)
Returns the roster for the user.
|
Presence |
getPresence(String user)
Returns the presence info for a particular user.
|
Presence |
getPresenceResource(String userWithResource)
Returns the presence info for a particular user's resource, or unavailable presence
if the user is offline or if no presence information is available, such as
when you are not subscribed to the user's presence updates.
|
List<Presence> |
getPresences(String user)
Returns a List of Presence objects for all of a user's current presences
or an unavailable presence if the user is unavailable (offline) or if no presence
information is available, such as when you are not subscribed to the user's presence
updates.
|
Roster.SubscriptionMode |
getSubscriptionMode()
Returns the subscription processing mode, which dictates what action
Smack will take when subscription requests from other users are made.
|
Set<RosterEntry> |
getUnfiledEntries()
Returns an unmodifiable set for the unfiled roster entries.
|
int |
getUnfiledEntryCount()
Returns a count of the unfiled entries in the roster.
|
boolean |
isLoaded()
Check if the roster is loaded.
|
boolean |
isRosterLoadedAtLogin()
Returns true if the roster will be loaded from the server when logging in.
|
boolean |
isRosterVersioningSupported()
Check if the server supports roster versioning.
|
boolean |
isSubscribedToMyPresence(String jid)
Check if the given JID is subscribed to the user's presence.
|
void |
reload()
Reloads the entire roster from the server.
|
void |
reloadAndWait()
Reload the roster and block until it is reloaded.
|
void |
removeEntry(RosterEntry entry)
Removes a roster entry from the roster.
|
boolean |
removeRosterListener(RosterListener rosterListener)
Removes a listener from this roster.
|
boolean |
removeRosterLoadedListener(RosterLoadedListener rosterLoadedListener)
Remove a roster loaded listener.
|
static void |
setDefaultSubscriptionMode(Roster.SubscriptionMode subscriptionMode)
Sets the default subscription processing mode to use when a new Roster is created.
|
void |
setRosterLoadedAtLogin(boolean rosterLoadedAtLogin)
Sets if the roster will be loaded from the server when logging in.
|
boolean |
setRosterStore(RosterStore rosterStore)
Set the roster store, may cause a roster reload
|
void |
setSubscriptionMode(Roster.SubscriptionMode subscriptionMode)
Sets the subscription processing mode, which dictates what action
Smack will take when subscription requests from other users are made.
|
protected boolean |
waitUntilLoaded() |
connection
public static Roster getInstanceFor(XMPPConnection connection)
This method will never return null
, instead if the user has not yet logged into
the server or is logged in anonymously all modifying methods of the returned roster object
like createEntry(String, String, String[])
,
removeEntry(RosterEntry)
, etc. except adding or removing
RosterListener
s will throw an IllegalStateException.
IllegalStateException
- if the connection is anonymouspublic static Roster.SubscriptionMode getDefaultSubscriptionMode()
Roster.SubscriptionMode.accept_all
.public static void setDefaultSubscriptionMode(Roster.SubscriptionMode subscriptionMode)
Roster.SubscriptionMode.accept_all
.subscriptionMode
- the default subscription mode to use for new Rosters.public Roster.SubscriptionMode getSubscriptionMode()
Roster.SubscriptionMode.accept_all
.If using the manual mode, a PacketListener should be registered that listens for Presence packets that have a type of
Presence.Type.subscribe
.public void setSubscriptionMode(Roster.SubscriptionMode subscriptionMode)
Roster.SubscriptionMode.accept_all
.If using the manual mode, a PacketListener should be registered that listens for Presence packets that have a type of
Presence.Type.subscribe
.subscriptionMode
- the subscription mode.public void reload() throws SmackException.NotLoggedInException, SmackException.NotConnectedException
SmackException.NotLoggedInException
- If not logged in.SmackException.NotConnectedException
public void reloadAndWait() throws SmackException.NotLoggedInException, SmackException.NotConnectedException, InterruptedException
public boolean setRosterStore(RosterStore rosterStore)
rosterStore
- protected boolean waitUntilLoaded() throws InterruptedException
InterruptedException
public boolean isLoaded()
public boolean addRosterListener(RosterListener rosterListener)
rosterListener
- a roster listener.getEntriesAndAddListener(RosterListener, RosterEntries)
public boolean removeRosterListener(RosterListener rosterListener)
rosterListener
- a roster listener.public boolean addRosterLoadedListener(RosterLoadedListener rosterLoadedListener)
rosterLoadedListener
- the listener to add.RosterLoadedListener
public boolean removeRosterLoadedListener(RosterLoadedListener rosterLoadedListener)
rosterLoadedListener
- the listener to remove.RosterLoadedListener
public RosterGroup createGroup(String name)
Note: you must add at least one entry to the group for the group to be kept after a logout/login. This is due to the way that XMPP stores group information.
name
- the name of the group.IllegalStateException
- if logged in anonymouslypublic void createEntry(String user, String name, String[] groups) throws SmackException.NotLoggedInException, SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
user
- the user. (e.g. johndoe@jabber.org)name
- the nickname of the user.groups
- the list of group names the entry will belong to, or null if the
the roster entry won't belong to a group.SmackException.NoResponseException
- if there was no response from the server.XMPPException.XMPPErrorException
- if an XMPP exception occurs.SmackException.NotLoggedInException
- If not logged in.SmackException.NotConnectedException
public void removeEntry(RosterEntry entry) throws SmackException.NotLoggedInException, SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
entry
- a roster entry.XMPPException.XMPPErrorException
- if an XMPP error occurs.SmackException.NotLoggedInException
- if not logged in.SmackException.NoResponseException
- SmackException if there was no response from the server.SmackException.NotConnectedException
IllegalStateException
- if connection is not logged in or logged in anonymouslypublic int getEntryCount()
public void getEntriesAndAddListener(RosterListener rosterListener, RosterEntries rosterEntries)
The method guarantees that the listener is only invoked after
RosterEntries.rosterEntires(Collection)
has been invoked, and that all roster events
that happen while rosterEntires(Collection)
is called are queued until the
method returns.
This guarantee makes this the ideal method to e.g. populate a UI element with the roster while
installing a RosterListener
to listen for subsequent roster events.
rosterListener
- the listener to installrosterEntries
- the roster entries callback interfacepublic Set<RosterEntry> getEntries()
public int getUnfiledEntryCount()
public Set<RosterEntry> getUnfiledEntries()
public RosterEntry getEntry(String user)
user
- the XMPP address of the user (eg "jsmith@example.com"). The address could be
in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource").public boolean contains(String user)
user
- the XMPP address of the user (eg "jsmith@example.com"). The
address could be in any valid format (e.g. "domain/resource",
"user@domain" or "user@domain/resource").public RosterGroup getGroup(String name)
name
- the name of the group.public int getGroupCount()
public Collection<RosterGroup> getGroups()
public Presence getPresence(String user)
If the user has several presences (one for each resource), then the presence with
highest priority will be returned. If multiple presences have the same priority,
the one with the "most available" presence mode will be returned. In order,
that's free to chat
,
available
,
away
,
extended away
, and
do not disturb
.
Note that presence information is received asynchronously. So, just after logging
in to the server, presence values for users in the roster may be unavailable
even if they are actually online. In other words, the value returned by this
method should only be treated as a snapshot in time, and may not accurately reflect
other user's presence instant by instant. If you need to track presence over time,
such as when showing a visual representation of the roster, consider using a
RosterListener
.
user
- an XMPP ID. The address could be in any valid format (e.g.
"domain/resource", "user@domain" or "user@domain/resource"). Any resource
information that's part of the ID will be discarded.public Presence getPresenceResource(String userWithResource)
userWithResource
- a fully qualified XMPP ID including a resource (user@domain/resource).public List<Presence> getAllPresences(String bareJid)
bareJid
- an XMPP ID, e.g. jdoe@example.com.public List<Presence> getAvailablePresences(String bareJid)
bareJid
- the bare JID from which the presences should be retrieved.public List<Presence> getPresences(String user)
user
- an XMPP ID, e.g. jdoe@example.com.public boolean isSubscribedToMyPresence(String jid)
If the JID is subscribed to the user's presence then it is allowed to see the presence and will get notified about presence changes. Also returns true, if the JID is the service name of the XMPP connection (the "XMPP domain"), i.e. the XMPP service is treated like having an implicit subscription to the users presence.
Note that if the roster is not loaded, then this method will always return false.jid
- public void setRosterLoadedAtLogin(boolean rosterLoadedAtLogin)
rosterLoadedAtLogin
- if the roster will be loaded from the server when logging in.public boolean isRosterLoadedAtLogin()
public boolean isRosterVersioningSupported()