support for delete bookmarks2
This commit is contained in:
parent
6923b2898c
commit
f1aa5f2cab
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -142,6 +142,15 @@ public class IqGenerator extends AbstractGenerator {
|
|||
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) {
|
||||
final Element item = new Element("item");
|
||||
item.setAttribute("id", avatar.sha1sum);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue