Skip to content

Commit ba09996

Browse files
committed
Don't allow PEP bookmarks if #publish-options is not advertised
1 parent fbef370 commit ba09996

7 files changed

Lines changed: 577 additions & 546 deletions

File tree

‎spec/bookmarks.js‎

Lines changed: 305 additions & 260 deletions
Large diffs are not rendered by default.

‎spec/chatbox.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
null, ['rosterGroupsFetched'], {},
5858
function (done, _converse) {
5959

60-
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
60+
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
6161
.then(function () {
6262
return test_utils.waitUntil(function () {
6363
return _converse.xmppstatus.get('fullname');
@@ -1228,7 +1228,7 @@
12281228
function (done, _converse) {
12291229

12301230
var contact, sent_stanza, IQ_id, stanza;
1231-
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
1231+
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
12321232
.then(function () {
12331233
return test_utils.waitUntil(function () {
12341234
return _converse.xmppstatus.get('fullname');
@@ -1842,7 +1842,7 @@
18421842
function (done, _converse) {
18431843

18441844
var contact, sent_stanza, IQ_id, stanza;
1845-
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
1845+
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
18461846
.then(function () {
18471847
return test_utils.waitUntil(function () {
18481848
return _converse.xmppstatus.get('fullname');
@@ -1989,7 +1989,7 @@
19891989
function (done, _converse) {
19901990

19911991
var contact, sent_stanza, IQ_id, stanza;
1992-
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
1992+
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
19931993
.then(function () {
19941994
return test_utils.waitUntil(function () {
19951995
return _converse.xmppstatus.get('fullname');

‎spec/chatroom.js‎

Lines changed: 234 additions & 248 deletions
Large diffs are not rendered by default.

‎spec/protocol.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
function (done, _converse) {
5656

5757
var contact, sent_stanza, IQ_id, stanza;
58-
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
58+
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
5959
.then(function () {
6060
return test_utils.waitUntil(function () {
6161
return _converse.xmppstatus.get('fullname');

‎src/converse-bookmarks.js‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,28 @@
7171
this.setBookmarkState();
7272
},
7373

74-
renderHeading () {
74+
renderBookmarkToggle () {
7575
const { _converse } = this.__super__,
7676
{ __ } = _converse;
77+
const bookmark_button = tpl_chatroom_bookmark_toggle(
78+
_.assignIn(this.model.toJSON(), {
79+
info_toggle_bookmark: __('Bookmark this room'),
80+
bookmarked: this.model.get('bookmarked')
81+
}));
82+
const close_button = this.el.querySelector('.close-chatbox-button');
83+
close_button.insertAdjacentHTML('afterend', bookmark_button);
84+
},
7785

86+
renderHeading () {
87+
this.__super__.renderHeading.apply(this, arguments);
88+
const { _converse } = this.__super__;
7889
if (_converse.allow_bookmarks) {
7990
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => {
8091
if (_.isNil(identity)) {
8192
return;
8293
}
83-
const div = document.createElement('div');
84-
div.innerHTML = this.generateHeadingHTML();
85-
86-
const bookmark_button = tpl_chatroom_bookmark_toggle(
87-
_.assignIn(
88-
this.model.toJSON(),
89-
{
90-
info_toggle_bookmark: __('Bookmark this room'),
91-
bookmarked: this.model.get('bookmarked')
92-
}
93-
));
94-
const close_button = div.querySelector('.close-chatbox-button');
95-
close_button.insertAdjacentHTML('afterend', bookmark_button);
96-
this.el.querySelector('.chat-head-chatroom').innerHTML = div.innerHTML;
97-
});
98-
} else {
99-
return this.__super__.renderHeading.apply(this, arguments);
94+
this.renderBookmarkToggle();
95+
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
10096
}
10197
},
10298

@@ -537,9 +533,14 @@
537533
if (!_converse.allow_bookmarks) {
538534
return;
539535
}
540-
// Only initialize bookmarks if the server supports PEP
541-
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => {
542-
if (_.isNil(identity)) {
536+
Promise.all([
537+
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid),
538+
_converse.api.disco.supports(Strophe.NS.PUBSUB+'#publish-options', _converse.bare_jid)
539+
]).then((args) => {
540+
const identity = args[0],
541+
options_support = args[1];
542+
543+
if (_.isNil(identity) || !options_support.supported) {
543544
_converse.emit('bookmarksInitialized');
544545
return;
545546
}

‎tests/mock.js‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@
119119
}, settings || {}));
120120
_converse.ChatBoxViews.prototype.trimChat = function () {};
121121

122-
var entity = _converse.api.disco.entities.get(_converse.bare_jid, true);
123-
entity.identities.create({
124-
'category': 'pubsub',
125-
'type': 'pep'
126-
});
127-
entity.waitUntilFeaturesDiscovered.resolve();
128-
129122
window.converse_disable_effects = true;
130123
return _converse;
131124
}

‎tests/utils.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
utils.waitUntil = waitUntilPromise.default;
1616

17-
utils.waitUntilFeatureSupportConfirmed = function (_converse, entity_jid, feature_name) {
17+
utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features) {
1818
var IQ_disco, stanza;
1919
return utils.waitUntil(function () {
2020
IQ_disco = _.filter(_converse.connection.IQ_stanzas, function (iq) {
@@ -24,13 +24,19 @@
2424
return !_.isUndefined(IQ_disco);
2525
}, 300).then(function () {
2626
var info_IQ_id = IQ_disco.nodeTree.getAttribute('id');
27-
stanza = $iq({
27+
var stanza = $iq({
2828
'type': 'result',
29-
'from': 'localhost',
29+
'from': entity_jid,
3030
'to': 'dummy@localhost/resource',
3131
'id': info_IQ_id
32-
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
33-
.c('feature', {'var': feature_name});
32+
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'});
33+
34+
_.forEach(identities, function (identity) {
35+
stanza.c('identity', {'category': 'pubsub', 'type': 'pep'}).up()
36+
});
37+
_.forEach(features, function (feature) {
38+
stanza.c('feature', {'var': feature}).up();
39+
});
3440
_converse.connection._dataRecv(utils.createRequest(stanza));
3541
});
3642
}

0 commit comments

Comments
 (0)