support for delete bookmarks2

This commit is contained in:
Daniel Gultsch 2019-09-28 01:21:19 +02:00
parent 6923b2898c
commit f1aa5f2cab
4 changed files with 512 additions and 474 deletions

View File

@ -19,6 +19,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
public abstract class AbstractGenerator {
@ -38,8 +39,6 @@ public abstract class AbstractGenerator {
"http://jabber.org/protocol/disco#info",
"urn:xmpp:avatar:metadata+notify",
Namespace.NICK+"+notify",
//Namespace.BOOKMARKS+"+notify",
Namespace.BOOKMARK+"+notify",
"urn:xmpp:ping",
"jabber:iq:version",
"http://jabber.org/protocol/chatstates"
@ -110,7 +109,8 @@ public abstract class AbstractGenerator {
}
public List<String> getFeatures(Account account) {
ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
final XmppConnection connection = account.getXmppConnection();
final ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
if (mXmppConnectionService.confirmMessages()) {
features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
}
@ -126,6 +126,12 @@ public abstract class AbstractGenerator {
if (mXmppConnectionService.broadcastLastActivity()) {
features.add(Namespace.IDLE);
}
if (connection != null && connection.getFeatures().bookmarks2()) {
features.add(Namespace.BOOKMARK+"+notify");
} else {
features.add(Namespace.BOOKMARKS+"+notify");
}
Collections.sort(features);
return features;
}

View File

@ -138,7 +138,16 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket deleteNode(String node) {
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB_OWNER);
pubsub.addChild("delete").setAttribute("node",node);
pubsub.addChild("delete").setAttribute("node", node);
return packet;
}
public IqPacket deleteItem(final String node, final String id) {
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
final Element retract = pubsub.addChild("retract");
retract.setAttribute("node", node);
retract.addChild("item").setAttribute("id", id);
return packet;
}
@ -154,9 +163,9 @@ public class IqGenerator extends AbstractGenerator {
return publishElement(namespace, element, "curent", options);
}
public IqPacket publishElement(final String namespace,final Element element, String id, final Bundle options) {
public IqPacket publishElement(final String namespace, final Element element, String id, final Bundle options) {
final Element item = new Element("item");
item.setAttribute("id",id);
item.setAttribute("id", id);
item.addChild(element);
return publish(namespace, item, options);
}
@ -518,7 +527,7 @@ public class IqGenerator extends AbstractGenerator {
options.putString("muc#roomconfig_allowinvites", "0");
options.putString("muc#roomconfig_enablearchiving", "1"); //prosody
options.putString("mam", "1"); //ejabberd community
options.putString("muc#roomconfig_mam","1"); //ejabberd saas
options.putString("muc#roomconfig_mam", "1"); //ejabberd saas
return options;
}
@ -531,7 +540,7 @@ public class IqGenerator extends AbstractGenerator {
options.putString("muc#roomconfig_changesubject", "0");
options.putString("muc#roomconfig_enablearchiving", "1"); //prosody
options.putString("mam", "1"); //ejabberd community
options.putString("muc#roomconfig_mam","1"); //ejabberd saas
options.putString("muc#roomconfig_mam", "1"); //ejabberd saas
return options;
}

View File

@ -314,11 +314,13 @@ public class XmppConnectionService extends Service {
mQuickConversationsService.considerSyncBackground(false);
fetchRosterFromServer(account);
fetchBookmarks2(account);
final XmppConnection connection = account.getXmppConnection();
/*if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
if (connection.getFeatures().bookmarks2()) {
fetchBookmarks2(account);
} else if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
fetchBookmarks(account);
}*/
}
final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval();
final boolean catchup = getMessageArchiveService().inCatchup(account);
if (flexible && catchup && account.getXmppConnection().isMamPreferenceAlways()) {
@ -1579,8 +1581,6 @@ public class XmppConnectionService extends Service {
if (response.getType() == IqPacket.TYPE.RESULT) {
final Element pubsub = response.findChild("pubsub", Namespace.PUBSUB);
final Collection<Bookmark> bookmarks = Bookmark.parseFromPubsub(pubsub, account);
Log.d(Config.LOGTAG,"bookmarks2 "+pubsub);
Log.d(Config.LOGTAG,"bookmarks2"+ bookmarks);
processBookmarksInitial(account, bookmarks, true);
}
}
@ -1621,13 +1621,32 @@ public class XmppConnectionService extends Service {
}
public void createBookmark(final Account account, final Bookmark bookmark) {
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());
} else if (connection.getFeatures().bookmarksConversion()) {
pushBookmarksPep(account);
} else {
pushBookmarksPrivateXml(account);
}
}
public void deleteBookmark(final Account account, final Bookmark bookmark) {
final XmppConnection connection = account.getXmppConnection();
if (connection.getFeatures().bookmarksConversion()) {
IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARK, bookmark.getJid().asBareJid().toEscapedString());
sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Log.d(Config.LOGTAG,packet.toString());
}
});
} else if (connection.getFeatures().bookmarksConversion()) {
pushBookmarksPep(account);
} else {
pushBookmarksPrivateXml(account);
}
}
private void pushBookmarksPrivateXml(Account account) {

View File

@ -1878,5 +1878,9 @@ public class XmppConnection implements Runnable {
public boolean stanzaIds() {
return hasDiscoFeature(account.getJid().asBareJid(), Namespace.STANZA_IDS);
}
public boolean bookmarks2() {
return true; //hasDiscoFeature(account.getJid().asBareJid(), Namespace.BOOKMARK);
}
}
}