code clean up for resumed processing

This commit is contained in:
Daniel Gultsch 2022-08-29 19:30:03 +02:00
parent f6ab3dd068
commit 7ea4f64ce4

View file

@ -694,52 +694,56 @@ public class XmppConnection implements Runnable {
} }
} }
private void processResumed(final Element resumed) { private void processResumed(final Element resumed) throws StateChangingException {
this.inSmacksSession = true; this.inSmacksSession = true;
this.isBound = true; this.isBound = true;
this.tagWriter.writeStanzaAsync(new RequestPacket(smVersion)); this.tagWriter.writeStanzaAsync(new RequestPacket(smVersion));
lastPacketReceived = SystemClock.elapsedRealtime(); lastPacketReceived = SystemClock.elapsedRealtime();
final String h = resumed.getAttribute("h"); final String h = resumed.getAttribute("h");
if (h == null) {
resetStreamId();
throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER);
}
final int serverCount;
try { try {
ArrayList<AbstractAcknowledgeableStanza> failedStanzas = new ArrayList<>(); serverCount = Integer.parseInt(h);
final boolean acknowledgedMessages; } catch (final NumberFormatException e) {
synchronized (this.mStanzaQueue) { resetStreamId();
final int serverCount = Integer.parseInt(h); throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER);
if (serverCount < stanzasSent) { }
Log.d( final ArrayList<AbstractAcknowledgeableStanza> failedStanzas = new ArrayList<>();
Config.LOGTAG, final boolean acknowledgedMessages;
account.getJid().asBareJid() + ": session resumed with lost packages"); synchronized (this.mStanzaQueue) {
stanzasSent = serverCount; if (serverCount < stanzasSent) {
} else { Log.d(
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": session resumed"); Config.LOGTAG,
} account.getJid().asBareJid() + ": session resumed with lost packages");
acknowledgedMessages = acknowledgeStanzaUpTo(serverCount); stanzasSent = serverCount;
for (int i = 0; i < this.mStanzaQueue.size(); ++i) { } else {
failedStanzas.add(mStanzaQueue.valueAt(i)); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": session resumed");
}
mStanzaQueue.clear();
} }
if (acknowledgedMessages) { acknowledgedMessages = acknowledgeStanzaUpTo(serverCount);
mXmppConnectionService.updateConversationUi(); for (int i = 0; i < this.mStanzaQueue.size(); ++i) {
failedStanzas.add(mStanzaQueue.valueAt(i));
} }
Log.d( mStanzaQueue.clear();
Config.LOGTAG, }
account.getJid().asBareJid() if (acknowledgedMessages) {
+ ": resending " mXmppConnectionService.updateConversationUi();
+ failedStanzas.size() }
+ " stanzas"); Log.d(
for (AbstractAcknowledgeableStanza packet : failedStanzas) { Config.LOGTAG,
if (packet instanceof MessagePacket) { account.getJid().asBareJid() + ": resending " + failedStanzas.size() + " stanzas");
MessagePacket message = (MessagePacket) packet; for (final AbstractAcknowledgeableStanza packet : failedStanzas) {
mXmppConnectionService.markMessage( if (packet instanceof MessagePacket) {
account, MessagePacket message = (MessagePacket) packet;
message.getTo().asBareJid(), mXmppConnectionService.markMessage(
message.getId(), account,
Message.STATUS_UNSEND); message.getTo().asBareJid(),
} message.getId(),
sendPacket(packet); Message.STATUS_UNSEND);
} }
} catch (final NumberFormatException ignored) { sendPacket(packet);
} }
Log.d( Log.d(
Config.LOGTAG, Config.LOGTAG,
@ -998,7 +1002,7 @@ public class XmppConnection implements Runnable {
Log.d( Log.d(
Config.LOGTAG, Config.LOGTAG,
account.getJid().asBareJid() account.getJid().asBareJid()
+ ": received NOP stream features" + ": received NOP stream features "
+ this.streamFeatures); + this.streamFeatures);
} }
} }