From b90a1fe1db9b19547093474da4b6af727570fd13 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 14 Feb 2017 17:19:45 +0100 Subject: [PATCH] bump mam namespace --- .../eu/siacs/conversations/entities/MucOptions.java | 4 ++-- .../siacs/conversations/generator/IqGenerator.java | 4 ++-- .../siacs/conversations/parser/MessageParser.java | 9 ++------- .../services/MessageArchiveService.java | 13 +++++++------ .../services/XmppConnectionService.java | 4 ++-- .../java/eu/siacs/conversations/utils/Xmlns.java | 1 + .../eu/siacs/conversations/xmpp/XmppConnection.java | 3 +-- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index bbc3e3701..aed90e21c 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Set; import eu.siacs.conversations.R; +import eu.siacs.conversations.utils.Xmlns; import eu.siacs.conversations.xmpp.forms.Data; import eu.siacs.conversations.xmpp.forms.Field; import eu.siacs.conversations.xmpp.jid.InvalidJidException; @@ -373,8 +374,7 @@ public class MucOptions { } public boolean mamSupport() { - // Update with "urn:xmpp:mam:1" once we support it - return hasFeature("urn:xmpp:mam:0"); + return hasFeature(Xmlns.MAM); } public boolean nonanonymous() { diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index bb602e3f6..c15480c81 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -230,10 +230,10 @@ public class IqGenerator extends AbstractGenerator { public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) { final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - final Element query = packet.query("urn:xmpp:mam:0"); + final Element query = packet.query(Xmlns.MAM); query.setAttribute("queryid", mam.getQueryId()); final Data data = new Data(); - data.setFormType("urn:xmpp:mam:0"); + data.setFormType(Xmlns.MAM); if (mam.muc()) { packet.setTo(mam.getWith()); } else if (mam.getWith()!=null) { diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index fd719da5d..d1e6a9f8a 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -300,15 +300,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece final boolean isForwarded; boolean isCarbon = false; String serverMsgId = null; - final Element fin = original.findChild("fin", "urn:xmpp:mam:0"); - if (fin != null) { - mXmppConnectionService.getMessageArchiveService().processFin(fin,original.getFrom()); - return; - } - final Element result = original.findChild("result","urn:xmpp:mam:0"); + final Element result = original.findChild("result",Xmlns.MAM); final MessageArchiveService.Query query = result == null ? null : mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid")); if (query != null && query.validFrom(original.getFrom())) { - Pair f = original.getForwardedMessagePacket("result", "urn:xmpp:mam:0"); + Pair f = original.getForwardedMessagePacket("result", Xmlns.MAM); if (f == null) { return; } diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index ab2f59b0b..83c50300f 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -14,6 +14,7 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.generator.AbstractGenerator; +import eu.siacs.conversations.utils.Xmlns; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnAdvancedStreamFeaturesLoaded; import eu.siacs.conversations.xmpp.OnIqPacketReceived; @@ -155,6 +156,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { + Element fin = packet.findChild("fin", Xmlns.MAM); if (packet.getType() == IqPacket.TYPE.TIMEOUT) { synchronized (MessageArchiveService.this.queries) { MessageArchiveService.this.queries.remove(query); @@ -162,7 +164,9 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { query.callback(false); } } - } else if (packet.getType() != IqPacket.TYPE.RESULT) { + } else if (packet.getType() == IqPacket.TYPE.RESULT && fin != null) { + processFin(fin); + } else { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString()); finalizeQuery(query, true); } @@ -215,12 +219,9 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { return queryInProgress(conversation, null); } - public void processFin(Element fin, Jid from) { - if (fin == null) { - return; - } + public void processFin(Element fin) { Query query = findQuery(fin.getAttribute("queryid")); - if (query == null || !query.validFrom(from)) { + if (query == null) { return; } boolean complete = fin.getAttributeAsBoolean("complete"); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 03fe14c3f..9f6a8f7ba 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3712,11 +3712,11 @@ public class XmppConnectionService extends Service { public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) { IqPacket request = new IqPacket(IqPacket.TYPE.GET); - request.addChild("prefs","urn:xmpp:mam:0"); + request.addChild("prefs",Xmlns.MAM); sendIqPacket(account, request, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - Element prefs = packet.findChild("prefs","urn:xmpp:mam:0"); + Element prefs = packet.findChild("prefs",Xmlns.MAM); if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) { callback.onPreferencesFetched(prefs); } else { diff --git a/src/main/java/eu/siacs/conversations/utils/Xmlns.java b/src/main/java/eu/siacs/conversations/utils/Xmlns.java index 3e7250599..ead2e45cd 100644 --- a/src/main/java/eu/siacs/conversations/utils/Xmlns.java +++ b/src/main/java/eu/siacs/conversations/utils/Xmlns.java @@ -7,4 +7,5 @@ public final class Xmlns { public static final String BYTE_STREAMS = "http://jabber.org/protocol/bytestreams"; public static final String HTTP_UPLOAD = "urn:xmpp:http:upload"; public static final String STANZA_IDS = "urn:xmpp:sid:0"; + public static final String MAM = "urn:xmpp:mam:1"; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 1caba5208..af4ca9b79 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1628,8 +1628,7 @@ public class XmppConnection implements Runnable { } public boolean mam() { - return hasDiscoFeature(account.getJid().toBareJid(), "urn:xmpp:mam:0") - || hasDiscoFeature(account.getServer(), "urn:xmpp:mam:0"); + return hasDiscoFeature(account.getJid().toBareJid(), Xmlns.MAM); } public boolean push() {