Fix and updates Bookmarks2 support

Support the stable version namespace and the new elements, including preserving
any extension content.
This commit is contained in:
Stephen Paul Weber 2023-11-10 11:40:51 +01:00 committed by Daniel Gultsch
parent 2b1730568d
commit f798102978
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
4 changed files with 17 additions and 2 deletions

View file

@ -25,6 +25,7 @@ public class Bookmark extends Element implements ListItem {
private final Account account;
private WeakReference<Conversation> conversation;
private Jid jid;
protected Element extensions = new Element("extensions", Namespace.BOOKMARKS2);
public Bookmark(final Account account, final Jid jid) {
super("conference");
@ -101,9 +102,18 @@ public class Bookmark extends Element implements ListItem {
bookmark.setBookmarkName(conference.getAttribute("name"));
bookmark.setAutojoin(conference.getAttributeAsBoolean("autojoin"));
bookmark.setNick(conference.findChildContent("nick"));
bookmark.setPassword(conference.findChildContent("password"));
final Element extensions = conference.findChild("extensions", Namespace.BOOKMARKS2);
if (extensions != null) {
bookmark.extensions = extensions;
}
return bookmark;
}
public Element getExtensions() {
return extensions;
}
public void setAutojoin(boolean autojoin) {
if (autojoin) {
this.setAttribute("autojoin", "true");

View file

@ -247,6 +247,7 @@ public class IqGenerator extends AbstractGenerator {
public Element publishBookmarkItem(final Bookmark bookmark) {
final String name = bookmark.getBookmarkName();
final String nick = bookmark.getNick();
final String password = bookmark.getPassword();
final boolean autojoin = bookmark.autojoin();
final Element conference = new Element("conference", Namespace.BOOKMARKS2);
if (name != null) {
@ -255,7 +256,11 @@ public class IqGenerator extends AbstractGenerator {
if (nick != null) {
conference.addChild("nick").setContent(nick);
}
if (password != null) {
conference.addChild("password").setContent(password);
}
conference.setAttribute("autojoin",String.valueOf(autojoin));
conference.addChild(bookmark.getExtensions());
return conference;
}

View file

@ -59,7 +59,7 @@ public final class Namespace {
public static final String PUSH = "urn:xmpp:push:0";
public static final String COMMANDS = "http://jabber.org/protocol/commands";
public static final String MUC_USER = "http://jabber.org/protocol/muc#user";
public static final String BOOKMARKS2 = "urn:xmpp:bookmarks:0";
public static final String BOOKMARKS2 = "urn:xmpp:bookmarks:1";
public static final String BOOKMARKS2_COMPAT = BOOKMARKS2 + "#compat";
public static final String INVITE = "urn:xmpp:invite";
public static final String PARS = "urn:xmpp:pars:0";

View file

@ -30,7 +30,7 @@ public class PublishOptions {
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#max_items", "max");
options.putString("pubsub#notify_delete", "true");
options.putString("pubsub#notify_retract", "true"); //one could also set notify=true on the retract