bookmarks2. introduce #compat namespace

This commit is contained in:
Daniel Gultsch 2019-09-28 13:14:59 +02:00
parent 94c592f213
commit f530e395ca
9 changed files with 26 additions and 24 deletions

View file

@ -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;

View file

@ -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<Jid, Bookmark> 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;
}

View file

@ -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");
}

View file

@ -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;
}

View file

@ -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");
}

View file

@ -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) {

View file

@ -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";
}

View file

@ -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);
}
}
}

View file

@ -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;
}