diff --git a/CHANGES.md b/CHANGES.md
index 3cc4937f7..69c632906 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@
### New features
- XEP-0382 Spoiler Messages (currently only for private chats)
+- Listen for new room bookmarks pushed from the user's PEP service.
### API changes
- New API method `_converse.disco.getIdentity` to check whether a JID has a given identity.
diff --git a/spec/bookmarks.js b/spec/bookmarks.js
index 43bcd6965..fd4b23fbc 100644
--- a/spec/bookmarks.js
+++ b/spec/bookmarks.js
@@ -12,6 +12,7 @@
} (this, function (jasmine, $, converse, utils, mock, test_utils) {
"use strict";
var $iq = converse.env.$iq,
+ $msg = converse.env.$msg,
Backbone = converse.env.Backbone,
Strophe = converse.env.Strophe,
_ = converse.env._,
@@ -278,51 +279,58 @@
describe("Bookmarks", function () {
- xit("can be pushed from the XMPP server", mock.initConverse(function (_converse) {
- // TODO
- /* The stored data is automatically pushed to all of the user's
- * connected resources.
- *
- * Publisher receives event notification
- * -------------------------------------
- *
- *
- *
- * -
- *
- *
- * JC
- *
- *
- *
- *
- *
- *
+ it("can be pushed from the XMPP server", mock.initConverseWithPromises(
+ ['send'], ['rosterGroupsFetched', 'connected'], {},
+ function (done, _converse) {
- *
- *
- *
- * -
- *
- *
- * JC
- *
- *
- *
- *
- *
- *
- */
+ test_utils.openControlBox().openRoomsPanel(_converse);
+
+ test_utils.waitUntil(function () {
+ return _converse.bookmarks;
+ }, 300).then(function () {
+ /* The stored data is automatically pushed to all of the user's
+ * connected resources.
+ *
+ * Publisher receives event notification
+ * -------------------------------------
+ *
+ *
+ *
+ * -
+ *
+ *
+ * JC
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+ var stanza = $msg({
+ 'from': 'dummy@localhost',
+ 'to': 'dummy@localhost/resource',
+ 'type': 'headline',
+ 'id': 'rnfoo1'
+ }).c('event', {'xmlns': 'http://jabber.org/protocol/pubsub#event'})
+ .c('items', {'node': 'storage:bookmarks'})
+ .c('item', {'id': 'current'})
+ .c('storage', {'xmlns': 'storage:bookmarks'})
+ .c('conference', {'name': 'The Play's the Thing',
+ 'autojoin': 'true',
+ 'jid':'theplay@conference.shakespeare.lit'})
+ .c('nick').t('JC');
+
+ _converse.connection._dataRecv(test_utils.createRequest(stanza));
+ expect(_converse.bookmarks.length).toBe(1);
+ expect(_converse.chatboxviews.get('theplay@conference.shakespeare.lit')).not.toBeUndefined();
+ done();
+ });
}));
it("can be retrieved from the XMPP server", mock.initConverseWithPromises(
diff --git a/src/converse-bookmarks.js b/src/converse-bookmarks.js
index c1560164a..ca3baa4c3 100644
--- a/src/converse-bookmarks.js
+++ b/src/converse-bookmarks.js
@@ -155,7 +155,7 @@
_.each(body.querySelectorAll('.chatroom-form-container'), u.removeElement);
body.insertAdjacentHTML(
- 'beforeend',
+ 'beforeend',
tpl_chatroom_bookmark_form({
heading: __('Bookmark this room'),
label_name: __('The name for this bookmark:'),
@@ -222,7 +222,7 @@
// configuration settings.
_converse.api.settings.update({
allow_bookmarks: true,
- hide_open_bookmarks: true
+ hide_open_bookmarks: true
});
// Promises exposed by this plugin
_converse.api.promises.add('bookmarksInitialized');
@@ -370,10 +370,13 @@
}
},
- onBookmarksReceived (deferred, iq) {
+ createBookmarksFromStanza (stanza) {
const bookmarks = sizzle(
- 'items[node="storage:bookmarks"] item[id="current"] storage conference',
- iq
+ 'items[node="storage:bookmarks"] '+
+ 'item#current '+
+ 'storage[xmlns="storage:bookmarks"] '+
+ 'conference',
+ stanza
)
_.forEach(bookmarks, (bookmark) => {
this.create({
@@ -383,6 +386,10 @@
'nick': bookmark.querySelector('nick').textContent
});
});
+ },
+
+ onBookmarksReceived (deferred, iq) {
+ this.createBookmarksFromStanza(iq);
if (!_.isUndefined(deferred)) {
return deferred.resolve();
}
@@ -557,6 +564,16 @@
]).then(initBookmarks)
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
+ _converse.on('connected', () => {
+ // Add a handler for bookmarks pushed from other connected clients
+ // (from the same user obviously)
+ _converse.connection.addHandler((message) => {
+ if (message.querySelector('event[xmlns="'+Strophe.NS.PUBSUB+'#event"]')) {
+ _converse.bookmarks.createBookmarksFromStanza(message);
+ }
+ }, null, 'message', 'headline', null, _converse.bare_jid);
+ });
+
const afterReconnection = function () {
if (!_converse.allow_bookmarks) {
return;