diff options
Diffstat (limited to '')
4 files changed, 57 insertions, 17 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java b/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java index 68a9ea213..545784586 100644 --- a/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java @@ -19,6 +19,7 @@ import de.pixart.messenger.entities.Account; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.utils.PhoneHelper; +import de.pixart.messenger.xmpp.XmppConnection; import de.pixart.messenger.xmpp.jingle.stanzas.Content; public abstract class AbstractGenerator { @@ -38,7 +39,6 @@ public abstract class AbstractGenerator { "http://jabber.org/protocol/disco#info", "urn:xmpp:avatar:metadata+notify", Namespace.NICK + "+notify", - Namespace.BOOKMARK + "+notify", "urn:xmpp:ping", "jabber:iq:version", "http://jabber.org/protocol/chatstates" @@ -112,7 +112,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)); } @@ -131,6 +132,11 @@ 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; } diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index 812ffcb9e..bb6355688 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java @@ -58,12 +58,6 @@ public class IqGenerator extends AbstractGenerator { return packet; } - public IqPacket purgeOfflineMessages() { - final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - packet.addChild("offline", Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL).addChild("purge"); - return packet; - } - public IqPacket versionResponse(final IqPacket request) { final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT); Element query = packet.query("jabber:iq:version"); @@ -97,6 +91,12 @@ public class IqGenerator extends AbstractGenerator { return packet; } + public IqPacket purgeOfflineMessages() { + final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); + packet.addChild("offline", Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL).addChild("purge"); + return packet; + } + protected IqPacket publish(final String node, final Element item, final Bundle options) { final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB); @@ -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); @@ -565,4 +574,4 @@ public class IqGenerator extends AbstractGenerator { } return packet; } -} +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index b2ae329c8..77f3bb78f 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -338,10 +338,12 @@ public class XmppConnectionService extends Service { mJingleConnectionManager.cancelInTransmission(); mQuickConversationsService.considerSyncBackground(false); fetchRosterFromServer(account); - fetchBookmarks2(account); - /*if (!account.getXmppConnection().getFeatures().bookmarksConversion()) { + final XmppConnection connection = account.getXmppConnection(); + 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()) { @@ -1819,8 +1821,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); } } @@ -1861,12 +1861,32 @@ public class XmppConnectionService extends Service { } public void createBookmark(final Account account, final Bookmark bookmark) { - final Element item = mIqGenerator.publishBookmarkItem(bookmark); - pushNodeAndEnforcePublishOptions(account, Namespace.BOOKMARK, item, bookmark.getJid().asBareJid().toEscapedString(), PublishOptions.persistentWhitelistAccessMaxItems()); + 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) { diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 1445b9b67..889819048 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -5,12 +5,13 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.SystemClock; import android.security.KeyChain; -import androidx.annotation.NonNull; import android.util.Base64; import android.util.Log; import android.util.Pair; import android.util.SparseArray; +import androidx.annotation.NonNull; + import org.xmlpull.v1.XmlPullParserException; import java.io.ByteArrayInputStream; @@ -1998,5 +1999,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); + } } }
\ No newline at end of file |