check mam preference for mam:2 namespace and purge offline only if set
This commit is contained in:
parent
f50e6e00ce
commit
7219f42ad2
|
@ -307,7 +307,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval();
|
final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval();
|
||||||
final boolean catchup = getMessageArchiveService().inCatchup(account);
|
final boolean catchup = getMessageArchiveService().inCatchup(account);
|
||||||
if (flexible && catchup) {
|
if (flexible && catchup && account.getXmppConnection().isMamPreferenceAlways()) {
|
||||||
sendIqPacket(account, mIqGenerator.purgeOfflineMessages(), (acc, packet) -> {
|
sendIqPacket(account, mIqGenerator.purgeOfflineMessages(), (acc, packet) -> {
|
||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
Log.d(Config.LOGTAG, acc.getJid().asBareJid() + ": successfully purged offline messages");
|
Log.d(Config.LOGTAG, acc.getJid().asBareJid() + ": successfully purged offline messages");
|
||||||
|
|
|
@ -47,7 +47,6 @@ import java.util.regex.Matcher;
|
||||||
|
|
||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSession;
|
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import javax.net.ssl.X509KeyManager;
|
import javax.net.ssl.X509KeyManager;
|
||||||
|
@ -75,7 +74,6 @@ import eu.siacs.conversations.services.MessageArchiveService;
|
||||||
import eu.siacs.conversations.services.NotificationService;
|
import eu.siacs.conversations.services.NotificationService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
import eu.siacs.conversations.utils.IP;
|
|
||||||
import eu.siacs.conversations.utils.Patterns;
|
import eu.siacs.conversations.utils.Patterns;
|
||||||
import eu.siacs.conversations.utils.Resolver;
|
import eu.siacs.conversations.utils.Resolver;
|
||||||
import eu.siacs.conversations.utils.SSLSocketHelper;
|
import eu.siacs.conversations.utils.SSLSocketHelper;
|
||||||
|
@ -157,6 +155,7 @@ public class XmppConnection implements Runnable {
|
||||||
private long lastConnect = 0;
|
private long lastConnect = 0;
|
||||||
private long lastSessionStarted = 0;
|
private long lastSessionStarted = 0;
|
||||||
private long lastDiscoStarted = 0;
|
private long lastDiscoStarted = 0;
|
||||||
|
private boolean isMamPreferenceAlways = false;
|
||||||
private AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0);
|
private AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0);
|
||||||
private AtomicBoolean mWaitForDisco = new AtomicBoolean(true);
|
private AtomicBoolean mWaitForDisco = new AtomicBoolean(true);
|
||||||
private AtomicBoolean mWaitingForSmCatchup = new AtomicBoolean(false);
|
private AtomicBoolean mWaitingForSmCatchup = new AtomicBoolean(false);
|
||||||
|
@ -1170,6 +1169,7 @@ public class XmppConnection implements Runnable {
|
||||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server caps came from cache");
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server caps came from cache");
|
||||||
disco.put(Jid.of(account.getServer()), discoveryResult);
|
disco.put(Jid.of(account.getServer()), discoveryResult);
|
||||||
}
|
}
|
||||||
|
discoverMamPreferences();
|
||||||
sendServiceDiscoveryInfo(account.getJid().asBareJid());
|
sendServiceDiscoveryInfo(account.getJid().asBareJid());
|
||||||
if (!requestDiscoItemsFirst) {
|
if (!requestDiscoItemsFirst) {
|
||||||
sendServiceDiscoveryItems(Jid.of(account.getServer()));
|
sendServiceDiscoveryItems(Jid.of(account.getServer()));
|
||||||
|
@ -1213,6 +1213,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() {
|
private void finalizeBind() {
|
||||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": online with resource " + account.getResource());
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": online with resource " + account.getResource());
|
||||||
if (bindListener != null) {
|
if (bindListener != null) {
|
||||||
|
|
Loading…
Reference in New Issue