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
......@@ -12,6 +12,7 @@
} (this, function (jasmine, $, converse, utils, mock, test_utils) {
"use strict";
var $iq = converse.env.$iq,
Backbone = converse.env.Backbone,
Strophe = converse.env.Strophe,
_ = converse.env._,
u = converse.env.utils;
......@@ -30,11 +31,15 @@
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();
spyOn(view, 'closeForm').and.callThrough();
test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
}, 300).then(function () {
var $bookmark = $(view.el).find('.icon-pushpin');
$bookmark[0].click();
expect(view.renderBookmarkForm).toHaveBeenCalled();
......@@ -129,6 +134,7 @@
// We ignore this IQ stanza... (unless it's an error stanza), so
// nothing to test for here.
done();
});
}));
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverseWithPromises(
......@@ -161,13 +167,18 @@
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
var view = _converse.chatboxviews.get('lounge@localhost');
var $bookmark_icon = $(view.el.querySelector('.icon-pushpin'));
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
}, 300).then(function () {
var bookmark_icon = view.el.querySelector('.icon-pushpin');
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeFalsy();
view.model.set('bookmarked', true);
expect($bookmark_icon.hasClass('button-on')).toBeTruthy();
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeTruthy();
view.model.set('bookmarked', false);
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeFalsy();
done();
});
}));
it("can be unbookmarked", mock.initConverseWithPromises(
......@@ -175,12 +186,18 @@
var sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ;
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
var jid = 'theplay@conference.shakespeare.lit';
var view = _converse.chatboxviews.get(jid);
test_utils.waitUntil(function () {
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
}, 300).then(function () {
spyOn(view, 'toggleBookmark').and.callThrough();
spyOn(_converse.bookmarks, 'sendBookmarkStanza').and.callThrough();
view.delegateEvents();
_converse.bookmarks.create({
'jid': view.model.get('jid'),
'autojoin': false,
......@@ -230,6 +247,7 @@
"</iq>"
);
done();
});
}));
});
......@@ -308,8 +326,12 @@
}));
it("can be retrieved from the XMPP server", mock.initConverseWithPromises(
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
function (done, _converse) {
test_utils.waitUntil(function () {
return _converse.bookmarks;
}, 300).then(function () {
/* Client requests all items
* -------------------------
*
......@@ -382,6 +404,7 @@
expect(_converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(_converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
done();
});
}));
describe("The rooms panel", function () {
......@@ -389,6 +412,10 @@
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.openControlBox().openRoomsPanel(_converse);
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
......@@ -454,11 +481,15 @@
"1st Bookmark  Bookmark with a very very long name that will be shortened  The Play&apos;s the Thing";
}, 300)
}).then(done);
});
}));
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 () {
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0];
......@@ -510,6 +541,7 @@
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
done();
});
});
}));
});
});
......@@ -521,6 +553,9 @@
{ hide_open_bookmarks: true },
function (done, _converse) {
test_utils.waitUntil(function () {
return _converse.bookmarks;
}, 300).then(function () {
test_utils.openControlBox().openRoomsPanel(_converse);
// XXX Create bookmarks view here, otherwise we need to mock stanza
// traffic for it to get created.
......@@ -551,6 +586,7 @@
view.close();
expect(u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom"))).toBeFalsy();
done();
});
}));
});
}));
......@@ -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');
......
......@@ -762,7 +762,6 @@
});
var view = _converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
spyOn(view, 'generateHeadingHTML').and.callThrough();
var features_stanza = $iq({
from: 'coven@chat.shakespeare.lit',
'id': IQ_id,
......@@ -791,10 +790,12 @@
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0);
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
expect(view.generateHeadingHTML).toHaveBeenCalled();
test_utils.waitUntil(function () {
return _.get(view.el.querySelector('.chatroom-description'), 'textContent');
}).then(function () {
expect($(view.el.querySelector('.chatroom-description')).text()).toBe('This is the description');
done();
});
}));
it("will specially mark messages in which you are mentioned",
......@@ -825,8 +826,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');
......@@ -890,6 +890,11 @@
_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.
......@@ -922,9 +927,14 @@
.c('status', {code: '110'});
_converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.saveAffiliationAndRole).toHaveBeenCalled();
expect($(view.el.querySelector('.configure-chatroom-button')).is(':visible')).toBeTruthy();
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'));
}, 300).then(function () {
expect($(view.el.querySelector('.configure-chatroom-button')).is(':visible')).toBeTruthy();
view.el.querySelector('.configure-chatroom-button').click();
/* Check that an IQ is sent out, asking for the
......@@ -1095,6 +1105,8 @@
expect($sent_stanza.find('field[var="muc#roomconfig_allowpm"] value').text()).toBe('moderators');
expect($sent_stanza.find('field[var="muc#roomconfig_presencebroadcast"] value').text()).toBe('moderator');
done();
});
});
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}));
......@@ -1973,6 +1985,9 @@
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');
......@@ -1991,6 +2006,7 @@
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'",
......@@ -2000,6 +2016,9 @@
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');
......@@ -2013,6 +2032,7 @@
// See the "leave" method on the ChatRoomView.
// expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
done();
});
}));
});
......
......@@ -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,13 +71,18 @@
this.setBookmarkState();
},
generateHeadingHTML () {
renderHeading () {
const { _converse } = this.__super__,
{ __ } = _converse,
html = this.__super__.generateHeadingHTML.apply(this, arguments);
{ __ } = _converse;
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 = html;
div.innerHTML = this.generateHeadingHTML();
const bookmark_button = tpl_chatroom_bookmark_toggle(
_.assignIn(
this.model.toJSON(),
......@@ -88,9 +93,11 @@
));
const close_button = div.querySelector('.close-chatbox-button');
close_button.insertAdjacentHTML('afterend', bookmark_button);
return div.innerHTML;
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,16 +530,25 @@
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)) {
_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))
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR))
.then(() => {
_converse.emit('bookmarksInitialized');
});
}).catch((e) => {
_converse.log(e, Strophe.LogLevel.ERROR);
_converse.emit('bookmarksInitialized');
});
};
Promise.all([
......
......@@ -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