From 2a05c3b707e7c0e00ce6b09b254638a95bbb06be Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Fri, 18 Jul 2014 14:38:48 +0200 Subject: [PATCH] Roster: merge the two registered ConnectionListeners --- .../java/org/jivesoftware/smack/Roster.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Roster.java b/smack-core/src/main/java/org/jivesoftware/smack/Roster.java index 7573c892f..3ac4b4974 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Roster.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/Roster.java @@ -131,6 +131,23 @@ public class Roster { // Listen for connection events connection.addConnectionListener(new AbstractConnectionListener() { + public void authenticated(XMPPConnection connection) { + // Anonymous users can't have a roster, but it is possible that a Roster instance is + // retrieved if getRoster() is called *before* connect(). So we have to check here + // again if it's an anonymous connection. + if (connection.isAnonymous()) + return; + if (!connection.isRosterLoadedAtLogin()) + return; + try { + Roster.this.reload(); + } + catch (SmackException e) { + LOGGER.log(Level.SEVERE, "Could not reload Roster", e); + return; + } + } + public void connectionClosed() { // Changes the presence available contacts to unavailable try { @@ -161,24 +178,6 @@ public class Roster { LOGGER.log(Level.SEVERE, "Could not reload Roster", e); } } - connection.addConnectionListener(new AbstractConnectionListener() { - public void authenticated(XMPPConnection connection) { - // Anonymous users can't have a roster, but it is possible that a Roster instance is - // retrieved if getRoster() is called *before* connect(). So we have to check here - // again if it's an anonymous connection. - if (connection.isAnonymous()) - return; - if (!connection.isRosterLoadedAtLogin()) - return; - try { - Roster.this.reload(); - } - catch (SmackException e) { - LOGGER.log(Level.SEVERE, "Could not reload Roster", e); - return; - } - } - }); } /**