From 32da5853d7570749a602c97093593da64f4906d8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 19 Jan 2024 16:01:07 +0100 Subject: [PATCH] track offline message queue --- .../services/XmppConnectionService.java | 5 +++++ .../conversations/xmpp/XmppConnection.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 41c467b15..8e79ef1b1 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -371,14 +371,19 @@ public class XmppConnectionService extends Service { } final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval(); final boolean catchup = getMessageArchiveService().inCatchup(account); + final boolean trackOfflineMessageRetrieval; if (flexible && catchup && account.getXmppConnection().isMamPreferenceAlways()) { + trackOfflineMessageRetrieval = false; sendIqPacket(account, mIqGenerator.purgeOfflineMessages(), (acc, packet) -> { if (packet.getType() == IqPacket.TYPE.RESULT) { Log.d(Config.LOGTAG, acc.getJid().asBareJid() + ": successfully purged offline messages"); } }); + } else { + trackOfflineMessageRetrieval = true; } sendPresence(account); + account.getXmppConnection().trackOfflineMessageRetrieval(trackOfflineMessageRetrieval); if (mPushManagementService.available(account)) { mPushManagementService.registerPushTokenOnServer(account); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 9141e1c70..0500517dc 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -165,6 +165,7 @@ public class XmppConnection implements Runnable { private boolean inSmacksSession = false; private boolean quickStartInProgress = false; private boolean isBound = false; + private boolean offlineMessagesRetrieved = false; private Element streamFeatures; private Element boundStreamFeatures; private StreamId streamId = null; @@ -2200,6 +2201,7 @@ public class XmppConnection implements Runnable { } private void finalizeBind() { + this.offlineMessagesRetrieved = false; if (bindListener != null) { bindListener.onBind(account); } @@ -2727,6 +2729,24 @@ public class XmppConnection implements Runnable { return mXmppConnectionService.getIqGenerator(); } + public void trackOfflineMessageRetrieval(boolean trackOfflineMessageRetrieval) { + if (trackOfflineMessageRetrieval) { + final IqPacket iqPing = new IqPacket(IqPacket.TYPE.GET); + iqPing.addChild("ping", Namespace.PING); + this.sendIqPacket( + iqPing, + (a, response) -> { + Log.d( + Config.LOGTAG, + account.getJid().asBareJid() + + ": received ping response after sending initial presence"); + XmppConnection.this.offlineMessagesRetrieved = true; + }); + } else { + this.offlineMessagesRetrieved = true; + } + } + private class MyKeyManager implements X509KeyManager { @Override public String chooseClientAlias(String[] strings, Principal[] principals, Socket socket) {