Commit 5f3761dc authored by JC Brand's avatar JC Brand

Only initialize bookmarks and show icon if PEP is supported

which we check by checking if the PEP identity is provided.
https://xmpp.org/extensions/xep-0163.html#support
parent bbe47b46
This diff is collapsed.
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp') test_utils.waitUntilFeatureSupportConfirmed(_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, 'vcard-temp') test_utils.waitUntilFeatureSupportConfirmed(_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, 'vcard-temp') test_utils.waitUntilFeatureSupportConfirmed(_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, 'vcard-temp') test_utils.waitUntilFeatureSupportConfirmed(_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');
......
This diff is collapsed.
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
var entities = _converse.disco_entities; var entities = _converse.disco_entities;
expect(entities.length).toBe(1); expect(entities.length).toBe(2); // We have an extra entity, which is the user's JID
expect(entities.get(_converse.domain).features.length).toBe(5); expect(entities.get(_converse.domain).features.length).toBe(5);
expect(entities.get(_converse.domain).identities.length).toBe(3); expect(entities.get(_converse.domain).identities.length).toBe(3);
expect(entities.get('localhost').features.where({'var': 'jabber:iq:version'}).length).toBe(1); expect(entities.get('localhost').features.where({'var': 'jabber:iq:version'}).length).toBe(1);
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
entities = _converse.disco_entities; entities = _converse.disco_entities;
expect(entities.length).toBe(4); expect(entities.length).toBe(5); // We have an extra entity, which is the user's JID
expect(entities.get(_converse.domain).identities.where({'category': 'conference'}).length).toBe(1); expect(entities.get(_converse.domain).identities.where({'category': 'conference'}).length).toBe(1);
expect(entities.get(_converse.domain).identities.where({'category': 'directory'}).length).toBe(1); expect(entities.get(_converse.domain).identities.where({'category': 'directory'}).length).toBe(1);
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, 'vcard-temp') test_utils.waitUntilFeatureSupportConfirmed(_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,26 +71,33 @@ ...@@ -71,26 +71,33 @@
this.setBookmarkState(); this.setBookmarkState();
}, },
generateHeadingHTML () { renderHeading () {
const { _converse } = this.__super__, const { _converse } = this.__super__,
{ __ } = _converse, { __ } = _converse;
html = this.__super__.generateHeadingHTML.apply(this, arguments);
if (_converse.allow_bookmarks) { if (_converse.allow_bookmarks) {
const div = document.createElement('div'); _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => {
div.innerHTML = html; if (_.isNil(identity)) {
const bookmark_button = tpl_chatroom_bookmark_toggle( return;
_.assignIn( }
this.model.toJSON(), const div = document.createElement('div');
{ div.innerHTML = this.generateHeadingHTML();
info_toggle_bookmark: __('Bookmark this room'),
bookmarked: this.model.get('bookmarked') const bookmark_button = tpl_chatroom_bookmark_toggle(
} _.assignIn(
)); this.model.toJSON(),
const close_button = div.querySelector('.close-chatbox-button'); {
close_button.insertAdjacentHTML('afterend', bookmark_button); info_toggle_bookmark: __('Bookmark this room'),
return div.innerHTML; 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);
} }
return html;
}, },
checkForReservedNick () { checkForReservedNick () {
...@@ -112,6 +119,9 @@ ...@@ -112,6 +119,9 @@
onBookmarked () { onBookmarked () {
const icon = this.el.querySelector('.icon-pushpin'); const icon = this.el.querySelector('.icon-pushpin');
if (_.isNull(icon)) {
return;
}
if (this.model.get('bookmarked')) { if (this.model.get('bookmarked')) {
icon.classList.add('button-on'); icon.classList.add('button-on');
} else { } else {
...@@ -520,14 +530,23 @@ ...@@ -520,14 +530,23 @@
if (!_converse.allow_bookmarks) { if (!_converse.allow_bookmarks) {
return; return;
} }
_converse.bookmarks = new _converse.Bookmarks(); // Only initialize bookmarks if the server supports PEP
_converse.bookmarks.fetchBookmarks().then(() => { _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => {
_converse.bookmarksview = new _converse.BookmarksView( if (_.isNil(identity)) {
{'model': _converse.bookmarks} _converse.emit('bookmarksInitialized');
); return;
}) }
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR)) _converse.bookmarks = new _converse.Bookmarks();
.then(() => { _converse.bookmarks.fetchBookmarks().then(() => {
_converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks}
);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR))
.then(() => {
_converse.emit('bookmarksInitialized');
});
}).catch((e) => {
_converse.log(e, Strophe.LogLevel.ERROR);
_converse.emit('bookmarksInitialized'); _converse.emit('bookmarksInitialized');
}); });
}; };
......
...@@ -1473,6 +1473,7 @@ ...@@ -1473,6 +1473,7 @@
this.connfeedback = new this.ConnectionFeedback(); this.connfeedback = new this.ConnectionFeedback();
this.XMPPStatus = Backbone.Model.extend({ this.XMPPStatus = Backbone.Model.extend({
initialize () { initialize () {
this.set({ this.set({
'status' : this.getStatus() 'status' : this.getStatus()
......
...@@ -326,6 +326,9 @@ ...@@ -326,6 +326,9 @@
); );
} }
const promises = [_converse.api.waitUntil('roomsAutoJoined')] const promises = [_converse.api.waitUntil('roomsAutoJoined')]
if (_converse.allow_bookmarks) {
promises.push( _converse.api.waitUntil('bookmarksInitialized'));
}
Promise.all(promises).then(() => { Promise.all(promises).then(() => {
_converse.api.rooms.open(jid); _converse.api.rooms.open(jid);
}); });
......
...@@ -118,6 +118,14 @@ ...@@ -118,6 +118,14 @@
'debug': false 'debug': false
}, 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,11 +14,12 @@ ...@@ -14,11 +14,12 @@
} }
utils.waitUntil = waitUntilPromise.default; utils.waitUntil = waitUntilPromise.default;
utils.waitUntilFeatureSupportConfirmed = function (_converse, feature_name) { utils.waitUntilFeatureSupportConfirmed = function (_converse, entity_jid, feature_name) {
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) {
return iq.nodeTree.querySelector('query[xmlns="http://jabber.org/protocol/disco#info"]'); return iq.nodeTree.querySelector('query[xmlns="http://jabber.org/protocol/disco#info"]') &&
iq.nodeTree.getAttribute('to') === entity_jid;
}).pop(); }).pop();
return !_.isUndefined(IQ_disco); return !_.isUndefined(IQ_disco);
}, 300).then(function () { }, 300).then(function () {
......
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