minor code clean up in XmppConnection class

This commit is contained in:
Daniel Gultsch 2020-12-31 10:27:06 +01:00
parent 0e54d8a2cf
commit 0569febf67
1 changed files with 42 additions and 49 deletions

View File

@ -107,9 +107,7 @@ public class XmppConnection implements Runnable {
private static final int PACKET_IQ = 0;
private static final int PACKET_MESSAGE = 1;
private static final int PACKET_PRESENCE = 2;
public final OnIqPacketReceived registrationResponseListener = new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
public final OnIqPacketReceived registrationResponseListener = (account, packet) -> {
if (packet.getType() == IqPacket.TYPE.RESULT) {
account.setOption(Account.OPTION_REGISTER, false);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": successfully registered new account on server");
@ -133,7 +131,6 @@ public class XmppConnection implements Runnable {
}
throw new StateChangingError(state);
}
}
};
protected final Account account;
private final Features features = new Features(this);
@ -160,10 +157,10 @@ public class XmppConnection implements Runnable {
private long lastSessionStarted = 0;
private long lastDiscoStarted = 0;
private boolean isMamPreferenceAlways = false;
private AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0);
private AtomicBoolean mWaitForDisco = new AtomicBoolean(true);
private AtomicBoolean mWaitingForSmCatchup = new AtomicBoolean(false);
private AtomicInteger mSmCatchupMessageCounter = new AtomicInteger(0);
private final AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0);
private final AtomicBoolean mWaitForDisco = new AtomicBoolean(true);
private final AtomicBoolean mWaitingForSmCatchup = new AtomicBoolean(false);
private final AtomicInteger mSmCatchupMessageCounter = new AtomicInteger(0);
private boolean mInteractive = false;
private int attempt = 0;
private OnPresencePacketReceived presenceListener = null;
@ -772,7 +769,7 @@ public class XmppConnection implements Runnable {
}
}
private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
private void processMessage(final Tag currentTag) throws IOException {
final MessagePacket packet = (MessagePacket) processPacket(currentTag, PACKET_MESSAGE);
if (!packet.valid()) {
Log.e(Config.LOGTAG, "encountered invalid message from='" + packet.getFrom() + "' to='" + packet.getTo() + "'");
@ -781,7 +778,7 @@ public class XmppConnection implements Runnable {
this.messageListener.onMessagePacketReceived(account, packet);
}
private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
private void processPresence(final Tag currentTag) throws IOException {
PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
if (!packet.valid()) {
Log.e(Config.LOGTAG, "encountered invalid presence from='" + packet.getFrom() + "' to='" + packet.getTo() + "'");
@ -835,7 +832,7 @@ public class XmppConnection implements Runnable {
return sslSocket;
}
private void processStreamFeatures(final Tag currentTag) throws XmlPullParserException, IOException {
private void processStreamFeatures(final Tag currentTag) throws IOException {
this.streamFeatures = tagReader.readElement(currentTag);
final boolean isSecure = features.encryptionEnabled || Config.ALLOW_NON_TLS_CONNECTIONS || account.isOnion();
final boolean needsBinding = !isBound && !account.isOptionSet(Account.OPTION_REGISTER);
@ -1326,7 +1323,7 @@ public class XmppConnection implements Runnable {
iq.query("http://jabber.org/protocol/disco#items");
this.sendIqPacket(iq, (account, packet) -> {
if (packet.getType() == IqPacket.TYPE.RESULT) {
HashSet<Jid> items = new HashSet<Jid>();
final HashSet<Jid> items = new HashSet<>();
final List<Element> elements = packet.query().getChildren();
for (final Element element : elements) {
if (element.getName().equals("item")) {
@ -1354,10 +1351,7 @@ public class XmppConnection implements Runnable {
private void sendEnableCarbons() {
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.addChild("enable", "urn:xmpp:carbons:2");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
this.sendIqPacket(iq, (account, packet) -> {
if (!packet.hasChild("error")) {
Log.d(Config.LOGTAG, account.getJid().asBareJid()
+ ": successfully enabled carbons");
@ -1366,11 +1360,10 @@ public class XmppConnection implements Runnable {
Log.d(Config.LOGTAG, account.getJid().asBareJid()
+ ": error enableing carbons " + packet.toString());
}
}
});
}
private void processStreamError(final Tag currentTag) throws XmlPullParserException, IOException {
private void processStreamError(final Tag currentTag) throws IOException {
final Element streamError = tagReader.readElement(currentTag);
if (streamError == null) {
return;
@ -1623,8 +1616,8 @@ public class XmppConnection implements Runnable {
}
public List<String> getMucServersWithholdAccount() {
List<String> servers = getMucServers();
servers.remove(account.getDomain());
final List<String> servers = getMucServers();
servers.remove(account.getDomain().toEscapedString());
return servers;
}
@ -1795,7 +1788,7 @@ public class XmppConnection implements Runnable {
}
}
private class StateChangingError extends Error {
private static class StateChangingError extends Error {
private final Account.State state;
public StateChangingError(Account.State state) {
@ -1803,7 +1796,7 @@ public class XmppConnection implements Runnable {
}
}
private class StateChangingException extends IOException {
private static class StateChangingException extends IOException {
private final Account.State state;
public StateChangingException(Account.State state) {