aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-01-21 14:49:29 +0100
committerChristian Schneppe <christian@pix-art.de>2018-01-21 14:49:29 +0100
commit25437cb60d1933158c6478cc291e3257c5c6db07 (patch)
treead21440fe24785a48b11ca2430f6b4fb178c13cb /src/main/java/de
parent89bea337c741d44d03a56457fe29ed5ba365d765 (diff)
disable offline messages. postpone prekey handling until after mam catchup
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java36
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java9
-rw-r--r--src/main/java/de/pixart/messenger/generator/MessageGenerator.java9
-rw-r--r--src/main/java/de/pixart/messenger/services/MessageArchiveService.java12
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java9
-rw-r--r--src/main/java/de/pixart/messenger/utils/Namespace.java1
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java4
7 files changed, 75 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
index eb15fbabc..ce5f1e4bb 100644
--- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
@@ -55,6 +55,7 @@ import de.pixart.messenger.xmpp.jid.InvalidJidException;
import de.pixart.messenger.xmpp.jid.Jid;
import de.pixart.messenger.xmpp.pep.PublishOptions;
import de.pixart.messenger.xmpp.stanzas.IqPacket;
+import de.pixart.messenger.xmpp.stanzas.MessagePacket;
public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
@@ -83,6 +84,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
private boolean pepBroken = false;
private int lastDeviceListNotificationHash = 0;
private AtomicBoolean changeAccessMode = new AtomicBoolean(false);
+ private Set<XmppAxolotlSession> postponedSessions = new HashSet<>(); //sessions stored here will receive after mam catchup treatment
@Override
public void onAdvancedStreamFeaturesAvailable(Account account) {
@@ -1241,6 +1243,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to encrypt message: " + e.getMessage());
return null;
}
+ //TODO: fix this for MUC PMs - Don't encrypt to all participants
if (!buildHeader(axolotlMessage, message.getConversation())) {
return null;
}
@@ -1333,9 +1336,36 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
private void postPreKeyMessageHandling(final XmppAxolotlSession session, int preKeyId, final boolean postpone) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": postPreKeyMessageHandling() preKeyId=" + preKeyId + ", postpone=" + Boolean.toString(postpone));
- //TODO: do not republish if we already removed this preKeyId
- publishBundlesIfNeeded(false, false);
+ if (postpone) {
+ postponedSessions.add(session);
+ } else {
+ //TODO: do not republish if we already removed this preKeyId
+ publishBundlesIfNeeded(false, false);
+ completeSession(session);
+ }
+ }
+
+ public void processPostponed() {
+ if (postponedSessions.size() > 0) {
+ publishBundlesIfNeeded(false, false);
+ }
+ Iterator<XmppAxolotlSession> iterator = postponedSessions.iterator();
+ while (iterator.hasNext()) {
+ completeSession(iterator.next());
+ iterator.remove();
+ }
+ }
+
+ private void completeSession(XmppAxolotlSession session) {
+ final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().toBareJid(), getOwnDeviceId());
+ axolotlMessage.addDevice(session);
+ try {
+ Jid jid = Jid.fromString(session.getRemoteAddress().getName());
+ MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateKeyTransportMessage(jid, axolotlMessage);
+ mXmppConnectionService.sendMessagePacket(account, packet);
+ } catch (InvalidJidException e) {
+ throw new Error("Remote addresses are created from jid and should convert back to jid", e);
+ }
}
public XmppAxolotlMessage.XmppAxolotlKeyTransportMessage processReceivingKeyTransportMessage(XmppAxolotlMessage message, final boolean postponePreKeyMessageHandling) {
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index ef2c10e6b..8275d7762 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -45,8 +45,7 @@ public class IqGenerator extends AbstractGenerator {
final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
packet.setId(request.getId());
packet.setTo(request.getFrom());
- final Element query = packet.addChild("query",
- "http://jabber.org/protocol/disco#info");
+ final Element query = packet.addChild("query", "http://jabber.org/protocol/disco#info");
query.setAttribute("node", request.query().getAttribute("node"));
final Element identity = query.addChild("identity");
identity.setAttribute("category", "client");
@@ -58,6 +57,12 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
+ public IqPacket purgeOfflineMessages() {
+ final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
+ packet.addChild("offline", Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL).addChild("purge");
+ return packet;
+ }
+
public IqPacket versionResponse(final IqPacket request) {
final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
Element query = packet.query("jabber:iq:version");
diff --git a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
index acdaedcbe..b795997e8 100644
--- a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
@@ -89,6 +89,15 @@ public class MessageGenerator extends AbstractGenerator {
return packet;
}
+ public MessagePacket generateKeyTransportMessage(Jid to, XmppAxolotlMessage axolotlMessage) {
+ MessagePacket packet = new MessagePacket();
+ packet.setType(MessagePacket.TYPE_CHAT);
+ packet.setTo(to);
+ packet.setAxolotlMessage(axolotlMessage.toElement());
+ packet.addChild("store", "urn:xmpp:hints");
+ return packet;
+ }
+
private static boolean recipientSupportsOmemo(Message message) {
Contact c = message.getContact();
return c != null && c.getPresences().allOrNonSupport(AxolotlService.PEP_DEVICE_LIST_NOTIFY);
diff --git a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java
index ab4be5eda..a7fd66515 100644
--- a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java
+++ b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java
@@ -221,6 +221,17 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
}
}
+ public boolean inCatchup(Account account) {
+ synchronized (this.queries) {
+ for (Query query : queries) {
+ if (query.account == account && query.isCatchup() && query.getWith() == null) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
public boolean queryInProgress(Conversation conversation, XmppConnectionService.OnMoreMessagesLoaded callback) {
synchronized (this.queries) {
for (Query query : queries) {
@@ -267,6 +278,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
if (query.isCatchup() && query.getActualMessageCount() > 0) {
mXmppConnectionService.getNotificationService().finishBacklog(true,query.getAccount());
}
+ query.account.getAxolotlService().processPostponed();
} else {
final Query nextQuery;
if (query.getPagingOrder() == PagingOrder.NORMAL) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 576050ec1..50eace97b 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -304,6 +304,15 @@ public class XmppConnectionService extends Service {
mJingleConnectionManager.cancelInTransmission();
fetchRosterFromServer(account);
fetchBookmarks(account);
+ final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval();
+ final boolean catchup = getMessageArchiveService().inCatchup(account);
+ if (flexible && catchup) {
+ sendIqPacket(account, mIqGenerator.purgeOfflineMessages(), (acc, packet) -> {
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ Log.d(Config.LOGTAG, acc.getJid().toBareJid() + ": successfully purged offline messages");
+ }
+ });
+ }
sendPresence(account);
if (mPushManagementService.available(account)) {
mPushManagementService.registerPushTokenOnServer(account);
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java
index d80b31d33..75e3855a4 100644
--- a/src/main/java/de/pixart/messenger/utils/Namespace.java
+++ b/src/main/java/de/pixart/messenger/utils/Namespace.java
@@ -16,4 +16,5 @@ public final class Namespace {
public static final String PUBSUB_PUBLISH_OPTIONS = "http://jabber.org/protocol/pubsub#publish-options";
public static final String PUBSUB_ERROR = "http://jabber.org/protocol/pubsub#errors";
public static final String NICK = "http://jabber.org/protocol/nick";
+ public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline";
}
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index acb15e068..0e168ca3b 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1711,6 +1711,10 @@ public class XmppConnection implements Runnable {
return hasDiscoFeature(account.getServer(), "urn:xmpp:reporting:reason:spam:0");
}
+ public boolean flexibleOfflineMessageRetrieval() {
+ return hasDiscoFeature(account.getServer(), Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL);
+ }
+
public boolean register() {
return hasDiscoFeature(account.getServer(), Namespace.REGISTER);
}