From 8c6e56b122a841986b2ecb3d71bff46ce42066dc Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 31 Jul 2015 13:27:03 +0200 Subject: [PATCH] Reset carbons state on clean disconnect and if session was not resumed. Fixes SMACK-688. --- .../smackx/carbons/CarbonManager.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java index 92e8134d3..28744f26e 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java @@ -19,6 +19,7 @@ package org.jivesoftware.smackx.carbons; import java.util.Map; import java.util.WeakHashMap; +import org.jivesoftware.smack.AbstractConnectionListener; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; @@ -65,6 +66,22 @@ public class CarbonManager extends Manager { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(CarbonExtension.NAMESPACE); + connection.addConnectionListener(new AbstractConnectionListener() { + @Override + public void connectionClosed() { + // Reset the state if the connection was cleanly closed. Note that this is not strictly necessary, + // because we also reset in authenticated() if the stream got not resumed, but for maximum correctness, + // also reset here. + enabled_state = false; + } + @Override + public void authenticated(XMPPConnection connection, boolean resumed) { + if (!resumed) { + // Non-resumed XMPP sessions always start with disabled carbons + enabled_state = false; + } + } + }); } /**