Commit ba099969 authored by JC Brand's avatar JC Brand

Don't allow PEP bookmarks if #publish-options is not advertised

parent fbef370b
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
it("can be bookmarked", mock.initConverseWithPromises( it("can be bookmarked", mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, function (done, _converse) { null, ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ; var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
...@@ -32,7 +37,6 @@ ...@@ -32,7 +37,6 @@
spyOn(_converse.connection, 'getUniqueId').and.callThrough(); spyOn(_converse.connection, 'getUniqueId').and.callThrough();
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC'); test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
var jid = 'theplay@conference.shakespeare.lit'; var jid = 'theplay@conference.shakespeare.lit';
var view = _converse.chatboxviews.get(jid); var view = _converse.chatboxviews.get(jid);
spyOn(view, 'renderBookmarkForm').and.callThrough(); spyOn(view, 'renderBookmarkForm').and.callThrough();
...@@ -136,11 +140,17 @@ ...@@ -136,11 +140,17 @@
// nothing to test for here. // nothing to test for here.
done(); done();
}); });
});
})); }));
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverseWithPromises( it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, function (done, _converse) { null, ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
var jid = 'lounge@localhost'; var jid = 'lounge@localhost';
_converse.bookmarks.create({ _converse.bookmarks.create({
'jid': jid, 'jid': jid,
...@@ -159,6 +169,7 @@ ...@@ -159,6 +169,7 @@
}); });
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy(); expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy();
done(); done();
});
})); }));
describe("when bookmarked", function () { describe("when bookmarked", function () {
...@@ -166,6 +177,11 @@ ...@@ -166,6 +177,11 @@
it("displays that it's bookmarked through its bookmark icon", mock.initConverseWithPromises( it("displays that it's bookmarked through its bookmark icon", mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, function (done, _converse) { null, ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
var view = _converse.chatboxviews.get('lounge@localhost'); var view = _converse.chatboxviews.get('lounge@localhost');
...@@ -180,11 +196,17 @@ ...@@ -180,11 +196,17 @@
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeFalsy(); expect(_.includes(bookmark_icon.classList, 'button-on')).toBeFalsy();
done(); done();
}); });
});
})); }));
it("can be unbookmarked", mock.initConverseWithPromises( it("can be unbookmarked", mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, function (done, _converse) { null, ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ; var sendIQ = _converse.connection.sendIQ;
...@@ -249,12 +271,20 @@ ...@@ -249,12 +271,20 @@
); );
done(); done();
}); });
});
})); }));
}); });
describe("and when autojoin is set", function () { describe("and when autojoin is set", function () {
it("will be be opened and joined automatically upon login", mock.initConverse(function (_converse) { it("will be be opened and joined automatically upon login", mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
spyOn(_converse.api.rooms, 'open'); spyOn(_converse.api.rooms, 'open');
var jid = 'theplay@conference.shakespeare.lit'; var jid = 'theplay@conference.shakespeare.lit';
var model = _converse.bookmarks.create({ var model = _converse.bookmarks.create({
...@@ -273,6 +303,8 @@ ...@@ -273,6 +303,8 @@
'nick': '' 'nick': ''
}); });
expect(_converse.api.rooms.open).toHaveBeenCalled(); expect(_converse.api.rooms.open).toHaveBeenCalled();
done();
});
})); }));
}); });
}); });
...@@ -283,8 +315,12 @@ ...@@ -283,8 +315,12 @@
['send'], ['rosterGroupsFetched', 'connected'], {}, ['send'], ['rosterGroupsFetched', 'connected'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.bare_jid,
[{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
test_utils.openControlBox().openRoomsPanel(_converse); test_utils.openControlBox().openRoomsPanel(_converse);
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return _converse.bookmarks; return _converse.bookmarks;
}, 300).then(function () { }, 300).then(function () {
...@@ -331,15 +367,18 @@ ...@@ -331,15 +367,18 @@
expect(_converse.chatboxviews.get('theplay@conference.shakespeare.lit')).not.toBeUndefined(); expect(_converse.chatboxviews.get('theplay@conference.shakespeare.lit')).not.toBeUndefined();
done(); done();
}); });
});
})); }));
it("can be retrieved from the XMPP server", mock.initConverseWithPromises( it("can be retrieved from the XMPP server", mock.initConverseWithPromises(
['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {}, ['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntil(function () { test_utils.waitUntilDiscoConfirmed(
return _converse.bookmarks; _converse, _converse.bare_jid,
}, 300).then(function () { [{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
/* Client requests all items /* Client requests all items
* ------------------------- * -------------------------
* *
...@@ -420,9 +459,11 @@ ...@@ -420,9 +459,11 @@
it("shows a list of bookmarks", mock.initConverseWithPromises( it("shows a list of bookmarks", mock.initConverseWithPromises(
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) { ['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntil(function () { test_utils.waitUntilDiscoConfirmed(
return _converse.bookmarks; _converse, _converse.bare_jid,
}, 300).then(function () { [{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
test_utils.openControlBox().openRoomsPanel(_converse); test_utils.openControlBox().openRoomsPanel(_converse);
var IQ_id; var IQ_id;
...@@ -495,9 +536,11 @@ ...@@ -495,9 +536,11 @@
it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises( it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises(
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) { ['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
test_utils.waitUntil(function () { test_utils.waitUntilDiscoConfirmed(
return _converse.bookmarks; _converse, _converse.bare_jid,
}, 300).then(function () { [{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
var IQ_id; var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) { expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0]; var stanza = call.args[0];
...@@ -561,9 +604,11 @@ ...@@ -561,9 +604,11 @@
{ hide_open_bookmarks: true }, { hide_open_bookmarks: true },
function (done, _converse) { function (done, _converse) {
test_utils.waitUntil(function () { test_utils.waitUntilDiscoConfirmed(
return _converse.bookmarks; _converse, _converse.bare_jid,
}, 300).then(function () { [{'category': 'pubsub', 'type': 'pep'}],
['http://jabber.org/protocol/pubsub#publish-options']
).then(function () {
test_utils.openControlBox().openRoomsPanel(_converse); test_utils.openControlBox().openRoomsPanel(_converse);
// XXX Create bookmarks view here, otherwise we need to mock stanza // XXX Create bookmarks view here, otherwise we need to mock stanza
// traffic for it to get created. // traffic for it to get created.
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp') test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.get('fullname');
...@@ -1228,7 +1228,7 @@ ...@@ -1228,7 +1228,7 @@
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza; var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp') test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.get('fullname');
...@@ -1842,7 +1842,7 @@ ...@@ -1842,7 +1842,7 @@
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza; var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp') test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.get('fullname');
...@@ -1989,7 +1989,7 @@ ...@@ -1989,7 +1989,7 @@
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza; var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp') test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.get('fullname');
......
...@@ -826,7 +826,7 @@ ...@@ -826,7 +826,7 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp') test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.get('fullname');
...@@ -891,10 +891,6 @@ ...@@ -891,10 +891,6 @@
_converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'}); _converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
}, 300).then(function () {
spyOn(view, 'saveAffiliationAndRole').and.callThrough(); spyOn(view, 'saveAffiliationAndRole').and.callThrough();
// We pretend this is a new room, so no disco info is returned. // We pretend this is a new room, so no disco info is returned.
...@@ -928,7 +924,6 @@ ...@@ -928,7 +924,6 @@
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.saveAffiliationAndRole).toHaveBeenCalled(); expect(view.saveAffiliationAndRole).toHaveBeenCalled();
expect($(view.el.querySelector('.toggle-chatbox-button')).is(':visible')).toBeTruthy(); expect($(view.el.querySelector('.toggle-chatbox-button')).is(':visible')).toBeTruthy();
expect($(view.el.querySelector('.toggle-bookmark')).is(':visible')).toBeTruthy();
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.configure-chatroom-button')); return !_.isNull(view.el.querySelector('.configure-chatroom-button'));
...@@ -1106,7 +1101,6 @@ ...@@ -1106,7 +1101,6 @@
expect($sent_stanza.find('field[var="muc#roomconfig_presencebroadcast"] value').text()).toBe('moderator'); expect($sent_stanza.find('field[var="muc#roomconfig_presencebroadcast"] value').text()).toBe('moderator');
done(); done();
}); });
});
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
...@@ -1985,9 +1979,6 @@ ...@@ -1985,9 +1979,6 @@
var view = _converse.chatboxviews.get('lounge@localhost'), var view = _converse.chatboxviews.get('lounge@localhost'),
trimmed_chatboxes = _converse.minimized_chats; trimmed_chatboxes = _converse.minimized_chats;
test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
}, 300).then(function () {
spyOn(view, 'minimize').and.callThrough(); spyOn(view, 'minimize').and.callThrough();
spyOn(view, 'maximize').and.callThrough(); spyOn(view, 'maximize').and.callThrough();
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
...@@ -2006,7 +1997,6 @@ ...@@ -2006,7 +1997,6 @@
expect(view.model.get('minimized')).toBeFalsy(); expect(view.model.get('minimized')).toBeFalsy();
expect(_converse.emit.calls.count(), 3); expect(_converse.emit.calls.count(), 3);
done(); done();
});
})); }));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", it("can be closed again by clicking a DOM element with class 'close-chatbox-button'",
...@@ -2016,9 +2006,6 @@ ...@@ -2016,9 +2006,6 @@
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
var view = _converse.chatboxviews.get('lounge@localhost'); var view = _converse.chatboxviews.get('lounge@localhost');
test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
}, 300).then(function () {
spyOn(view, 'close').and.callThrough(); spyOn(view, 'close').and.callThrough();
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
spyOn(view, 'leave'); spyOn(view, 'leave');
...@@ -2032,7 +2019,6 @@ ...@@ -2032,7 +2019,6 @@
// See the "leave" method on the ChatRoomView. // See the "leave" method on the ChatRoomView.
// expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object)); // expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
done(); done();
});
})); }));
}); });
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza; var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp') test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.get('fullname');
......
...@@ -71,32 +71,28 @@ ...@@ -71,32 +71,28 @@
this.setBookmarkState(); this.setBookmarkState();
}, },
renderHeading () { renderBookmarkToggle () {
const { _converse } = this.__super__, const { _converse } = this.__super__,
{ __ } = _converse; { __ } = _converse;
const bookmark_button = tpl_chatroom_bookmark_toggle(
_.assignIn(this.model.toJSON(), {
info_toggle_bookmark: __('Bookmark this room'),
bookmarked: this.model.get('bookmarked')
}));
const close_button = this.el.querySelector('.close-chatbox-button');
close_button.insertAdjacentHTML('afterend', bookmark_button);
},
renderHeading () {
this.__super__.renderHeading.apply(this, arguments);
const { _converse } = this.__super__;
if (_converse.allow_bookmarks) { if (_converse.allow_bookmarks) {
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => { _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => {
if (_.isNil(identity)) { if (_.isNil(identity)) {
return; return;
} }
const div = document.createElement('div'); this.renderBookmarkToggle();
div.innerHTML = this.generateHeadingHTML(); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
const bookmark_button = tpl_chatroom_bookmark_toggle(
_.assignIn(
this.model.toJSON(),
{
info_toggle_bookmark: __('Bookmark this room'),
bookmarked: this.model.get('bookmarked')
}
));
const close_button = div.querySelector('.close-chatbox-button');
close_button.insertAdjacentHTML('afterend', bookmark_button);
this.el.querySelector('.chat-head-chatroom').innerHTML = div.innerHTML;
});
} else {
return this.__super__.renderHeading.apply(this, arguments);
} }
}, },
...@@ -537,9 +533,14 @@ ...@@ -537,9 +533,14 @@
if (!_converse.allow_bookmarks) { if (!_converse.allow_bookmarks) {
return; return;
} }
// Only initialize bookmarks if the server supports PEP Promise.all([
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => { _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid),
if (_.isNil(identity)) { _converse.api.disco.supports(Strophe.NS.PUBSUB+'#publish-options', _converse.bare_jid)
]).then((args) => {
const identity = args[0],
options_support = args[1];
if (_.isNil(identity) || !options_support.supported) {
_converse.emit('bookmarksInitialized'); _converse.emit('bookmarksInitialized');
return; return;
} }
......
...@@ -119,13 +119,6 @@ ...@@ -119,13 +119,6 @@
}, settings || {})); }, settings || {}));
_converse.ChatBoxViews.prototype.trimChat = function () {}; _converse.ChatBoxViews.prototype.trimChat = function () {};
var entity = _converse.api.disco.entities.get(_converse.bare_jid, true);
entity.identities.create({
'category': 'pubsub',
'type': 'pep'
});
entity.waitUntilFeaturesDiscovered.resolve();
window.converse_disable_effects = true; window.converse_disable_effects = true;
return _converse; return _converse;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
} }
utils.waitUntil = waitUntilPromise.default; utils.waitUntil = waitUntilPromise.default;
utils.waitUntilFeatureSupportConfirmed = function (_converse, entity_jid, feature_name) { utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features) {
var IQ_disco, stanza; var IQ_disco, stanza;
return utils.waitUntil(function () { return utils.waitUntil(function () {
IQ_disco = _.filter(_converse.connection.IQ_stanzas, function (iq) { IQ_disco = _.filter(_converse.connection.IQ_stanzas, function (iq) {
...@@ -24,13 +24,19 @@ ...@@ -24,13 +24,19 @@
return !_.isUndefined(IQ_disco); return !_.isUndefined(IQ_disco);
}, 300).then(function () { }, 300).then(function () {
var info_IQ_id = IQ_disco.nodeTree.getAttribute('id'); var info_IQ_id = IQ_disco.nodeTree.getAttribute('id');
stanza = $iq({ var stanza = $iq({
'type': 'result', 'type': 'result',
'from': 'localhost', 'from': entity_jid,
'to': 'dummy@localhost/resource', 'to': 'dummy@localhost/resource',
'id': info_IQ_id 'id': info_IQ_id
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'}) }).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'});
.c('feature', {'var': feature_name});
_.forEach(identities, function (identity) {
stanza.c('identity', {'category': 'pubsub', 'type': 'pep'}).up()
});
_.forEach(features, function (feature) {
stanza.c('feature', {'var': feature}).up();
});
_converse.connection._dataRecv(utils.createRequest(stanza)); _converse.connection._dataRecv(utils.createRequest(stanza));
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment