Carbon stuff

This commit is contained in:
Paul Schaub 2020-06-01 10:24:49 +02:00
parent 86d8fd9e84
commit 1122ece79d
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
4 changed files with 25 additions and 21 deletions

View File

@ -2,10 +2,13 @@ package org.mercury_im.messenger.xmpp;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.ReconnectionListener;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.sasl.SASLErrorException;
import org.jivesoftware.smackx.carbons.CarbonManager;
import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.xmpp.exception.InvalidCredentialsException;
import org.mercury_im.messenger.xmpp.exception.ServerUnreachableException;
@ -103,39 +106,49 @@ public class MercuryConnection {
private final ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) {
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " connected PRE");
state.onNext(state.getValue()
.withConnectivity(ConnectivityState.connected)
.withAuthenticated(false));
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " connected POST");
}
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " authenticated PRE");
state.onNext(state.getValue()
.withConnectivity(ConnectivityState.connected)
.withAuthenticated(true)
.withResumed(resumed));
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " authenticated POST");
if (!resumed) {
initialConnectionSetup();
}
}
@Override
public void connectionClosed() {
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " connectionClosed PRE");
state.onNext(state.getValue()
.withConnectivity(ConnectivityState.disconnected)
.withAuthenticated(false));
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " connectionClosed POST");
}
@Override
public void connectionClosedOnError(Exception e) {
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " connectionClosedError PRE");
state.onNext(state.getValue()
.withConnectivity(ConnectivityState.disconnected)
.withAuthenticated(false));
LOGGER.log(Level.INFO, "ConnectionListener " + account.getAddress() + " connectionClosedError POST");
}
};
private void initialConnectionSetup() {
ReconnectionManager.getInstanceFor((AbstractXMPPConnection) getConnection())
.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int seconds) {
LOGGER.log(Level.FINER, "Reconnecting connection " + getAccount().getAddress() + " in " + seconds + " seconds.");
}
@Override
public void reconnectionFailed(Exception e) {
LOGGER.log(Level.WARNING, "Reconnection of connection " + getAccount().getAddress() + " failed.", e);
}
});
}
}

View File

@ -127,18 +127,6 @@ public class MercuryConnectionManager {
public void bindConnection(MercuryConnection connection) {
rosterStoreBinder.setRosterStoreOn(connection);
ReconnectionManager.getInstanceFor((AbstractXMPPConnection) connection.getConnection())
.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int seconds) {
LOGGER.log(Level.FINER, "Reconnecting connection " + connection.getAccountId() + " in " + seconds + " seconds.");
}
@Override
public void reconnectionFailed(Exception e) {
LOGGER.log(Level.WARNING, "Reconnection of connection " + connection.getAccountId() + " failed.", e);
}
});
}
private void handleOptionalAccountChangedEvent(MercuryConnection connection, Optional<Account> event) {

View File

@ -1,6 +1,7 @@
package org.mercury_im.messenger.xmpp;
import org.jivesoftware.smack.ReconnectionManager;
import org.jivesoftware.smackx.carbons.CarbonManager;
import org.jivesoftware.smackx.iqversion.VersionManager;
import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.receipts.DeliveryReceiptManager;
@ -18,5 +19,7 @@ public class SmackConfig {
DeliveryReceiptManager.setDefaultAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.ifIsSubscribed);
StableUniqueStanzaIdManager.setEnabledByDefault(true);
CarbonManager.setEnabledByDefault(true);
}
}

@ -1 +1 @@
Subproject commit ccc785062e9b04513302c898e3015c2ff2d7fb91
Subproject commit e2a196fa52222a6816dd850ee8380335a90f7850