1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Do not send unavailable on disconnect() when not authenticated

This commit is contained in:
Florian Schmaus 2018-02-20 09:44:05 +01:00
parent 1bd3469fec
commit 5e25491877

View file

@ -706,8 +706,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* *
*/ */
public void disconnect() { public void disconnect() {
Presence unavailablePresence = null;
if (isAuthenticated()) {
unavailablePresence = new Presence(Presence.Type.unavailable);
}
try { try {
disconnect(new Presence(Presence.Type.unavailable)); disconnect(unavailablePresence);
} }
catch (NotConnectedException e) { catch (NotConnectedException e) {
LOGGER.log(Level.FINEST, "Connection is already disconnected", e); LOGGER.log(Level.FINEST, "Connection is already disconnected", e);
@ -722,15 +726,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* stanza(/packet) is set with online information, but most XMPP servers will deliver the full * stanza(/packet) is set with online information, but most XMPP servers will deliver the full
* presence stanza(/packet) with whatever data is set. * presence stanza(/packet) with whatever data is set.
* *
* @param unavailablePresence the presence stanza(/packet) to send during shutdown. * @param unavailablePresence the optional presence stanza to send during shutdown.
* @throws NotConnectedException * @throws NotConnectedException
*/ */
public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException { public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException {
if (unavailablePresence != null) {
try { try {
sendStanza(unavailablePresence); sendStanza(unavailablePresence);
} catch (InterruptedException e) {
LOGGER.log(Level.FINE,
"Was interrupted while sending unavailable presence. Continuing to disconnect the connection",
e);
} }
catch (InterruptedException e) {
LOGGER.log(Level.FINE, "Was interrupted while sending unavailable presence. Continuing to disconnect the connection", e);
} }
shutdown(); shutdown();
callConnectionClosedListener(); callConnectionClosedListener();