diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index ba18c2734..798eb2aac 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -277,11 +277,6 @@ public class XMPPBOSHConnection extends XMPPConnection { } } - // Set presence to online. - if (config.isSendPresence()) { - sendPacket(new Presence(Presence.Type.available)); - } - // Indicate that we're now authenticated. authenticated = true; anonymous = false; @@ -296,6 +291,14 @@ public class XMPPBOSHConnection extends XMPPConnection { debugger.userHasLogged(user); } callConnectionAuthenticatedListener(); + + // Set presence to online. It is important that this is done after + // callConnectionAuthenticatedListener(), as this call will also + // eventually load the roster. And we should load the roster before we + // send the initial presence. + if (config.isSendPresence()) { + sendPacket(new Presence(Presence.Type.available)); + } } public void loginAnonymously() throws XMPPException, SmackException, IOException { diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 264140540..6d797eb7f 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -274,11 +274,6 @@ public class XMPPTCPConnection extends XMPPConnection { authenticated = true; anonymous = false; - // Set presence to online. - if (config.isSendPresence()) { - sendPacket(new Presence(Presence.Type.available)); - } - // Stores the authentication for future reconnection setLoginInfo(username, password, resource); @@ -290,6 +285,14 @@ public class XMPPTCPConnection extends XMPPConnection { debugger.userHasLogged(user); } callConnectionAuthenticatedListener(); + + // Set presence to online. It is important that this is done after + // callConnectionAuthenticatedListener(), as this call will also + // eventually load the roster. And we should load the roster before we + // send the initial presence. + if (config.isSendPresence()) { + sendPacket(new Presence(Presence.Type.available)); + } } @Override