Don't show headlines from full JID if allow_non_roster_messaging is false

This commit is contained in:
JC Brand 2017-02-24 14:03:26 +00:00
parent 6dfc82da0b
commit 5c445a0268
2 changed files with 28 additions and 27 deletions

View File

@ -24,8 +24,6 @@
* <body>SORRY FOR THIS ADVERT</body * <body>SORRY FOR THIS ADVERT</body
* </message * </message
*/ */
test_utils.openControlBox();
test_utils.openContactsPanel(_converse);
sinon.spy(utils, 'isHeadlineMessage'); sinon.spy(utils, 'isHeadlineMessage');
runs(function () { runs(function () {
var stanza = $msg({ var stanza = $msg({
@ -46,10 +44,8 @@
}); });
})); }));
it("will open and display headline messages", mock.initConverse(function (_converse) { it("will open and display headline messages", mock.initConverse(function (_converse) {
/* /* <message from='notify.example.com'
* <message from='notify.example.com'
* to='romeo@im.example.com' * to='romeo@im.example.com'
* type='headline' * type='headline'
* xml:lang='en'> * xml:lang='en'>
@ -62,8 +58,6 @@
* </x> * </x>
* </message> * </message>
*/ */
test_utils.openControlBox();
test_utils.openContactsPanel(_converse);
sinon.spy(utils, 'isHeadlineMessage'); sinon.spy(utils, 'isHeadlineMessage');
runs(function () { runs(function () {
var stanza = $msg({ var stanza = $msg({
@ -90,5 +84,28 @@
utils.isHeadlineMessage.restore(); // unwraps utils.isHeadlineMessage.restore(); // unwraps
}); });
})); }));
it("will not show a headline messages from a full JID if allow_non_roster_messaging is false", mock.initConverse(function (_converse) {
_converse.allow_non_roster_messaging = false;
sinon.spy(utils, 'isHeadlineMessage');
runs(function () {
var stanza = $msg({
'type': 'headline',
'from': 'andre5114@jabber.snc.ru/Spark',
'to': 'dummy@localhost',
'xml:lang': 'en'
})
.c('nick').t('gpocy').up()
.c('body').t('Здравствуйте друзья');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
});
waits(250);
runs(function () {
expect(_.without('controlbox', _converse.chatboxviews.keys()).length).toBe(0);
expect(utils.isHeadlineMessage.called).toBeTruthy();
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
utils.isHeadlineMessage.restore(); // unwraps
});
}));
}); });
})); }));

View File

@ -17,24 +17,6 @@
var _ = converse.env._, var _ = converse.env._,
utils = converse.env.utils; utils = converse.env.utils;
var onHeadlineMessage = function (message) {
/* Handler method for all incoming messages of type "headline".
*/
var from_jid = message.getAttribute('from');
var _converse = this.__super__._converse;
if (utils.isHeadlineMessage(message)) {
_converse.chatboxes.create({
'id': from_jid,
'jid': from_jid,
'fullname': from_jid,
'type': 'headline'
}).createMessage(message, undefined, message);
_converse.emit('message', message);
}
return true;
};
converse.plugins.add('converse-headline', { converse.plugins.add('converse-headline', {
overrides: { overrides: {
@ -107,10 +89,12 @@
}); });
var onHeadlineMessage = function (message) { var onHeadlineMessage = function (message) {
/* Handler method for all incoming messages of type "headline". /* Handler method for all incoming messages of type "headline". */
*/
var from_jid = message.getAttribute('from'); var from_jid = message.getAttribute('from');
if (utils.isHeadlineMessage(message)) { if (utils.isHeadlineMessage(message)) {
if (_.includes(from_jid, '@') && !_converse.allow_non_roster_messaging) {
return;
}
_converse.chatboxes.create({ _converse.chatboxes.create({
'id': from_jid, 'id': from_jid,
'jid': from_jid, 'jid': from_jid,