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 @@
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
test_utils.waitUntilFeatureSupportConfirmed(_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, 'vcard-temp')
test_utils.waitUntilFeatureSupportConfirmed(_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, 'vcard-temp')
test_utils.waitUntilFeatureSupportConfirmed(_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, 'vcard-temp')
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
......
This diff is collapsed.
......@@ -79,7 +79,7 @@
_converse.connection._dataRecv(test_utils.createRequest(stanza));
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).identities.length).toBe(3);
expect(entities.get('localhost').features.where({'var': 'jabber:iq:version'}).length).toBe(1);
......@@ -159,7 +159,7 @@
_converse.connection._dataRecv(test_utils.createRequest(stanza));
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': 'directory'}).length).toBe(1);
done();
......
......@@ -55,7 +55,7 @@
function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'localhost', 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
......
......@@ -71,26 +71,33 @@
this.setBookmarkState();
},
generateHeadingHTML () {
renderHeading () {
const { _converse } = this.__super__,
{ __ } = _converse,
html = this.__super__.generateHeadingHTML.apply(this, arguments);
{ __ } = _converse;
if (_converse.allow_bookmarks) {
const div = document.createElement('div');
div.innerHTML = html;
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);
return div.innerHTML;
_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);
}
return html;
},
checkForReservedNick () {
......@@ -112,6 +119,9 @@
onBookmarked () {
const icon = this.el.querySelector('.icon-pushpin');
if (_.isNull(icon)) {
return;
}
if (this.model.get('bookmarked')) {
icon.classList.add('button-on');
} else {
......@@ -520,14 +530,23 @@
if (!_converse.allow_bookmarks) {
return;
}
_converse.bookmarks = new _converse.Bookmarks();
_converse.bookmarks.fetchBookmarks().then(() => {
_converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks}
);
})
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR))
.then(() => {
// Only initialize bookmarks if the server supports PEP
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then((identity) => {
if (_.isNil(identity)) {
_converse.emit('bookmarksInitialized');
return;
}
_converse.bookmarks = new _converse.Bookmarks();
_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');
});
};
......
......@@ -1473,6 +1473,7 @@
this.connfeedback = new this.ConnectionFeedback();
this.XMPPStatus = Backbone.Model.extend({
initialize () {
this.set({
'status' : this.getStatus()
......
......@@ -326,6 +326,9 @@
);
}
const promises = [_converse.api.waitUntil('roomsAutoJoined')]
if (_converse.allow_bookmarks) {
promises.push( _converse.api.waitUntil('bookmarksInitialized'));
}
Promise.all(promises).then(() => {
_converse.api.rooms.open(jid);
});
......
......@@ -118,6 +118,14 @@
'debug': false
}, 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,11 +14,12 @@
}
utils.waitUntil = waitUntilPromise.default;
utils.waitUntilFeatureSupportConfirmed = function (_converse, feature_name) {
utils.waitUntilFeatureSupportConfirmed = function (_converse, entity_jid, feature_name) {
var IQ_disco, stanza;
return utils.waitUntil(function () {
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();
return !_.isUndefined(IQ_disco);
}, 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