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