diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-12-14 20:39:11 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-12-14 20:39:11 +0100 |
commit | 7967a35cd3fa9983a559c937a7ab24ef815d87c6 (patch) | |
tree | fba2f5092021aca60c501eaa414bf9c9c8029dde /src/main/java/de | |
parent | 483d0e260489d82cbc72998a4610fab37d19c92a (diff) |
check mam preference for mam:2 namespace and purge offline only if set
Diffstat (limited to 'src/main/java/de')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 2 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index b4fba14b2..ba583b304 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -322,7 +322,7 @@ public class XmppConnectionService extends Service { } final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval(); final boolean catchup = getMessageArchiveService().inCatchup(account); - if (flexible && catchup) { + if (flexible && catchup && account.getXmppConnection().isMamPreferenceAlways()) { sendIqPacket(account, mIqGenerator.purgeOfflineMessages(), (acc, packet) -> { if (packet.getType() == IqPacket.TYPE.RESULT) { Log.d(Config.LOGTAG, acc.getJid().asBareJid() + ": successfully purged offline messages"); diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index a40670c55..c92653444 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -162,6 +162,7 @@ public class XmppConnection implements Runnable { private long lastConnect = 0; 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); @@ -1195,6 +1196,7 @@ public class XmppConnection implements Runnable { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server caps came from cache"); disco.put(Jid.of(account.getServer()), discoveryResult); } + discoverMamPreferences(); sendServiceDiscoveryInfo(account.getJid().asBareJid()); if (!requestDiscoItemsFirst) { sendServiceDiscoveryItems(Jid.of(account.getServer())); @@ -1238,6 +1240,21 @@ public class XmppConnection implements Runnable { }); } + private void discoverMamPreferences() { + IqPacket request = new IqPacket(IqPacket.TYPE.GET); + request.addChild("prefs", MessageArchiveService.Version.MAM_2.namespace); + sendIqPacket(request, (account, response) -> { + if (response.getType() == IqPacket.TYPE.RESULT) { + Element prefs = response.findChild("prefs", MessageArchiveService.Version.MAM_2.namespace); + isMamPreferenceAlways = "always".equals(prefs == null ? null : prefs.getAttribute("default")); + } + }); + } + + public boolean isMamPreferenceAlways() { + return isMamPreferenceAlways; + } + private void finalizeBind() { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": online with resource " + account.getResource()); if (bindListener != null) { |