Roster: merge the two registered ConnectionListeners

This commit is contained in:
Georg Lukas 2014-07-18 14:38:48 +02:00 committed by Florian Schmaus
parent d35fd16a21
commit 2a05c3b707
1 changed files with 17 additions and 18 deletions

View File

@ -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;
}
}
});
}
/**