mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 12:32:06 +01:00
The connection's roster can be accessed before the user actually logs in
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2195 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
b6f3741854
commit
15df277ced
1 changed files with 8 additions and 20 deletions
|
@ -323,8 +323,7 @@ public class XMPPConnection {
|
||||||
// We're done with the collector, so explicitly cancel it.
|
// We're done with the collector, so explicitly cancel it.
|
||||||
collector.cancel();
|
collector.cancel();
|
||||||
|
|
||||||
// Create the roster.
|
// Load the entire roster from the server.
|
||||||
this.roster = new Roster(this);
|
|
||||||
roster.reload();
|
roster.reload();
|
||||||
|
|
||||||
// Set presence to online.
|
// Set presence to online.
|
||||||
|
@ -403,31 +402,17 @@ public class XMPPConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the roster for the user logged into the server. If the user has not yet
|
* Returns the roster for the user logged into the server. If the user has not yet
|
||||||
* logged into the server (or if the user is logged in anonymously), this method will return
|
* logged into the server this method will return a non-loaded roster that the user can
|
||||||
|
* configure. If the user is logged in anonymously, this method will return
|
||||||
* <tt>null</tt>.
|
* <tt>null</tt>.
|
||||||
*
|
*
|
||||||
* @return the user's roster, or <tt>null</tt> if the user has not logged in yet.
|
* @return the user's roster, a non-loaded roster if the user has not yet
|
||||||
|
* logged in, or <tt>null</tt> if the user is logged in anonymously.
|
||||||
*/
|
*/
|
||||||
public Roster getRoster() {
|
public Roster getRoster() {
|
||||||
if (roster == null) {
|
if (roster == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// If this is the first time the user has asked for the roster after calling
|
|
||||||
// login, we want to wait up to 2 seconds for the server to send back the
|
|
||||||
// user's roster. This behavior shields API users from having to worry about the
|
|
||||||
// fact that roster operations are asynchronous, although they'll still have to
|
|
||||||
// listen for changes to the roster. Note: because of this waiting logic, internal
|
|
||||||
// Smack code should be wary about calling the getRoster method, and may need to
|
|
||||||
// access the roster object directly.
|
|
||||||
int elapsed = 0;
|
|
||||||
while (!roster.rosterInitialized && elapsed <= 2000) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(500);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
}
|
|
||||||
elapsed += 500;
|
|
||||||
}
|
|
||||||
return roster;
|
return roster;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,6 +720,9 @@ public class XMPPConnection {
|
||||||
// Make note of the fact that we're now connected.
|
// Make note of the fact that we're now connected.
|
||||||
connected = true;
|
connected = true;
|
||||||
|
|
||||||
|
// Create the roster.
|
||||||
|
this.roster = new Roster(this);
|
||||||
|
|
||||||
// Notify that a new connection has been established
|
// Notify that a new connection has been established
|
||||||
connectionEstablished(this);
|
connectionEstablished(this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue