fail pending messages on policy violation. fixes #3735

This commit is contained in:
Daniel Gultsch 2020-05-22 18:23:53 +02:00
parent ed4d7bff92
commit 88cc097732
1 changed files with 35 additions and 16 deletions

View File

@ -1339,6 +1339,7 @@ public class XmppConnection implements Runnable {
this.lastConnect = SystemClock.elapsedRealtime();
final String text = streamError.findChildContent("text");
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": policy violation. " + text);
failPendingMessages(text);
throw new StateChangingException(Account.State.POLICY_VIOLATION);
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": stream error " + streamError.toString());
@ -1346,6 +1347,24 @@ public class XmppConnection implements Runnable {
}
}
private void failPendingMessages(final String error) {
synchronized (this.mStanzaQueue) {
for (int i = 0; i < mStanzaQueue.size(); ++i) {
final AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i);
if (stanza instanceof MessagePacket) {
final MessagePacket packet = (MessagePacket) stanza;
final String id = packet.getId();
final Jid to = packet.getTo();
mXmppConnectionService.markMessage(account,
to.asBareJid(),
id,
Message.STATUS_SEND_FAILED,
error);
}
}
}
}
private void sendStartStream() throws IOException {
final Tag stream = Tag.start("stream:stream");
stream.setAttribute("to", account.getServer());