Commit ba099969 authored by JC Brand's avatar JC Brand

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

parent fbef370b
This diff is collapsed.
......@@ -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');
......
This diff is collapsed.
......@@ -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));
});
}
......
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