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

View file

@ -142,6 +142,15 @@ public class IqGenerator extends AbstractGenerator {
return packet; 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;
}
public IqPacket publishAvatar(Avatar avatar, Bundle options) { public IqPacket publishAvatar(Avatar avatar, Bundle options) {
final Element item = new Element("item"); final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum); item.setAttribute("id", avatar.sha1sum);

View file

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

View file

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