From f530e395ca1259a4ed366fd74f33d8750a13e92f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 28 Sep 2019 13:14:59 +0200 Subject: [PATCH] bookmarks2. introduce #compat namespace --- src/main/java/eu/siacs/conversations/Config.java | 1 + .../siacs/conversations/entities/Bookmark.java | 8 ++------ .../generator/AbstractGenerator.java | 2 +- .../conversations/generator/IqGenerator.java | 6 ++++-- .../conversations/parser/MessageParser.java | 7 +++---- .../services/XmppConnectionService.java | 5 ++--- .../eu/siacs/conversations/xml/Namespace.java | 3 ++- .../siacs/conversations/xmpp/XmppConnection.java | 2 +- .../conversations/xmpp/pep/PublishOptions.java | 16 ++++++++++------ 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 47e2db24c..c9bd3c819 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -99,6 +99,7 @@ public final class Config { public static final boolean OMEMO_PADDING = false; public static final boolean PUT_AUTH_TAG_INTO_KEY = true; + public static final boolean USE_BOOKMARKS2 = false; public static final boolean DISABLE_PROXY_LOOKUP = false; //useful to debug ibb public static final boolean USE_DIRECT_JINGLE_CANDIDATES = true; diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 8f71c46b9..9d708ce17 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -3,19 +3,15 @@ package eu.siacs.conversations.entities; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; -import eu.siacs.conversations.Config; import eu.siacs.conversations.utils.StringUtils; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; @@ -65,7 +61,7 @@ public class Bookmark extends Element implements ListItem { return Collections.emptyMap(); } final Element items = pubsub.findChild("items"); - if (items != null && Namespace.BOOKMARK.equals(items.getAttribute("node"))) { + if (items != null && Namespace.BOOKMARKS2.equals(items.getAttribute("node"))) { final Map bookmarks = new HashMap<>(); for(Element item : items.getChildren()) { if (item.getName().equals("item")) { @@ -92,7 +88,7 @@ public class Bookmark extends Element implements ListItem { } public static Bookmark parseFromItem(Element item, Account account) { - final Element conference = item.findChild("conference", Namespace.BOOKMARK); + final Element conference = item.findChild("conference", Namespace.BOOKMARKS2); if (conference == null) { return null; } diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java index 1341a19f5..df15f39e2 100644 --- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java @@ -127,7 +127,7 @@ public abstract class AbstractGenerator { features.add(Namespace.IDLE); } if (connection != null && connection.getFeatures().bookmarks2()) { - features.add(Namespace.BOOKMARK+"+notify"); + features.add(Namespace.BOOKMARKS2 +"+notify"); } else { features.add(Namespace.BOOKMARKS+"+notify"); } diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 54085d638..7c7456776 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -126,7 +126,7 @@ public class IqGenerator extends AbstractGenerator { } public IqPacket retrieveBookmarks() { - return retrieve(Namespace.BOOKMARK, null); + return retrieve(Namespace.BOOKMARKS2, null); } public IqPacket publishNick(String nick) { @@ -243,13 +243,15 @@ public class IqGenerator extends AbstractGenerator { public Element publishBookmarkItem(final Bookmark bookmark) { final String name = bookmark.getBookmarkName(); final String nick = bookmark.getNick(); - final Element conference = new Element("conference", Namespace.BOOKMARK); + final boolean autojoin = bookmark.autojoin(); + final Element conference = new Element("conference", Namespace.BOOKMARKS2); if (name != null) { conference.setAttribute("name", name); } if (nick != null) { conference.addChild("nick").setContent(nick); } + conference.setAttribute("autojoin",String.valueOf(autojoin)); return conference; } diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 2a63b68e6..dc00c0277 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -6,7 +6,6 @@ import android.util.Pair; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -233,7 +232,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring bookmark PEP event because bookmark conversion was not detected"); } - } else if (Namespace.BOOKMARK.equals(node) && account.getJid().asBareJid().equals(from)) { + } else if (Namespace.BOOKMARKS2.equals(node) && account.getJid().asBareJid().equals(from)) { final Element item = items.findChild("item"); final Element retract = items.findChild("retract"); if (item != null) { @@ -261,7 +260,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (Namespace.NICK.equals(node)) { Log.d(Config.LOGTAG, "parsing nick delete event from " + from); setNick(account, from, null); - } else if (Namespace.BOOKMARK.equals(node) && account.getJid().asBareJid().equals(from)) { + } else if (Namespace.BOOKMARKS2.equals(node) && account.getJid().asBareJid().equals(from)) { account.setBookmarks(Collections.emptyMap()); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": deleted bookmarks node"); } @@ -270,7 +269,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece private void parsePurgeEvent(final Element event, final Jid from, final Account account) { final Element purge = event.findChild("purge"); final String node = purge == null ? null : purge.getAttribute("node"); - if (Namespace.BOOKMARK.equals(node) && account.getJid().asBareJid().equals(from)) { + if (Namespace.BOOKMARKS2.equals(node) && account.getJid().asBareJid().equals(from)) { account.setBookmarks(Collections.emptyMap()); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": purged bookmarks"); } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index f3a1bf626..a3ba0b6d0 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -57,7 +57,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; @@ -1639,7 +1638,7 @@ public class XmppConnectionService extends Service { final XmppConnection connection = account.getXmppConnection(); if (connection.getFeatures().bookmarks2()) { final Element item = mIqGenerator.publishBookmarkItem(bookmark); - pushNodeAndEnforcePublishOptions(account, Namespace.BOOKMARK, item, bookmark.getJid().asBareJid().toEscapedString(), PublishOptions.persistentWhitelistAccessMaxItems()); + pushNodeAndEnforcePublishOptions(account, Namespace.BOOKMARKS2, item, bookmark.getJid().asBareJid().toEscapedString(), PublishOptions.persistentWhitelistAccessMaxItems()); } else if (connection.getFeatures().bookmarksConversion()) { pushBookmarksPep(account); } else { @@ -1651,7 +1650,7 @@ public class XmppConnectionService extends Service { account.removeBookmark(bookmark); final XmppConnection connection = account.getXmppConnection(); if (connection.getFeatures().bookmarksConversion()) { - IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARK, bookmark.getJid().asBareJid().toEscapedString()); + IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARKS2, bookmark.getJid().asBareJid().toEscapedString()); sendIqPacket(account, request, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { diff --git a/src/main/java/eu/siacs/conversations/xml/Namespace.java b/src/main/java/eu/siacs/conversations/xml/Namespace.java index 18314d79b..4be004b97 100644 --- a/src/main/java/eu/siacs/conversations/xml/Namespace.java +++ b/src/main/java/eu/siacs/conversations/xml/Namespace.java @@ -33,5 +33,6 @@ public final class Namespace { public static final String JINGLE_ENCRYPTED_TRANSPORT = "urn:xmpp:jingle:jet:0"; public static final String JINGLE_ENCRYPTED_TRANSPORT_OMEMO = "urn:xmpp:jingle:jet-omemo:0"; public static final String MUC_USER = "http://jabber.org/protocol/muc#user"; - public static final String BOOKMARK = "urn:xmpp:bookmarks:0"; + public static final String BOOKMARKS2 = "urn:xmpp:bookmarks:0"; + public static final String BOOKMARKS2_COMPAT = BOOKMARKS2+"#compat"; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 3e09c8205..003ea39a2 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1880,7 +1880,7 @@ public class XmppConnection implements Runnable { } public boolean bookmarks2() { - return hasDiscoFeature(account.getJid().asBareJid(), Namespace.BOOKMARK); + return Config.USE_BOOKMARKS2 || hasDiscoFeature(account.getJid().asBareJid(), Namespace.BOOKMARKS2_COMPAT); } } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/pep/PublishOptions.java b/src/main/java/eu/siacs/conversations/xmpp/pep/PublishOptions.java index 959323cc6..62f65ee1f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/pep/PublishOptions.java +++ b/src/main/java/eu/siacs/conversations/xmpp/pep/PublishOptions.java @@ -14,23 +14,27 @@ public class PublishOptions { public static Bundle openAccess() { final Bundle options = new Bundle(); - options.putString("pubsub#access_model","open"); + options.putString("pubsub#access_model", "open"); return options; } public static Bundle persistentWhitelistAccess() { final Bundle options = new Bundle(); - options.putString("pubsub#persist_items","true"); - options.putString("pubsub#access_model","whitelist"); + options.putString("pubsub#persist_items", "true"); + options.putString("pubsub#access_model", "whitelist"); return options; } public static Bundle persistentWhitelistAccessMaxItems() { final Bundle options = new Bundle(); - options.putString("pubsub#persist_items","true"); + options.putString("pubsub#persist_items", "true"); options.putString("pubsub#access_model", "whitelist"); - options.putString("pubsub#send_last_published_item","never"); - options.putString("pubsub#max_items","128"); //YOLO! + options.putString("pubsub#send_last_published_item", "never"); + options.putString("pubsub#max_items", "128"); //YOLO! + + options.putString("pubsub#notify_delete", "true"); + options.putString("pubsub#notify_retract", "true"); //one could also set notify=true on the retract + return options; }