Commit 82ee7f69 authored by JC Brand's avatar JC Brand

Don't ignore messages sent to different resource

But make this behavior configurable. Updates #647
parent b82e0f31
...@@ -414,6 +414,15 @@ these values. ...@@ -414,6 +414,15 @@ these values.
*Beware*: a malicious script could use these tokens to assume your identity *Beware*: a malicious script could use these tokens to assume your identity
and inject fake chat messages. and inject fake chat messages.
filter_by_resource
------------------
* Default: ``false``
Before version 1.0.3 converse.js would ignore received messages if they were
intended for a different resource then the current user had. It was decided to
drop this restriction but leave it configurable.
forward_messages forward_messages
---------------- ----------------
......
...@@ -413,6 +413,19 @@ ...@@ -413,6 +413,19 @@
runs(function () {}); runs(function () {});
}); });
describe("when received from someone else", function () {
it("will cause the chat area to be scrolled down only if it was at the bottom already", function () {
// TODO
});
});
describe("when sent by the current user", function () {
it("will always cause the chat area to be scrolled down", function () {
// TODO
});
});
it("can be received which will open a chatbox and be displayed inside it", function () { it("can be received which will open a chatbox and be displayed inside it", function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var message = 'This is a received message'; var message = 'This is a received message';
...@@ -456,22 +469,50 @@ ...@@ -456,22 +469,50 @@
}.bind(converse)); }.bind(converse));
}.bind(converse)); }.bind(converse));
it("is ignored if it's intended for a different resource", function () { it("is ignored if it's intended for a different resource and filter_by_resource is set to true", function () {
// Send a message from a different resource // Send a message from a different resource
var message, sender_jid, msg;
spyOn(converse, 'log'); spyOn(converse, 'log');
spyOn(converse.chatboxes, 'getChatBox'); spyOn(converse.chatboxes, 'getChatBox').andCallThrough();
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; runs(function () {
var msg = $msg({ converse.filter_by_resource = true;
from: sender_jid, sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
to: converse.bare_jid+'/'+"some-other-resource", msg = $msg({
type: 'chat', from: sender_jid,
id: (new Date()).getTime() to: converse.bare_jid+'/'+"some-other-resource",
}).c('body').t("This message will not be shown").up() type: 'chat',
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); id: (new Date()).getTime()
converse.chatboxes.onMessage(msg); }).c('body').t("This message will not be shown").up()
expect(converse.log).toHaveBeenCalledWith( .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
"onMessage: Ignoring incoming message intended for a different resource: dummy@localhost/some-other-resource", "info"); converse.chatboxes.onMessage(msg);
expect(converse.chatboxes.getChatBox).not.toHaveBeenCalled(); });
waits(50);
runs(function () {
expect(converse.log).toHaveBeenCalledWith(
"onMessage: Ignoring incoming message intended for a different resource: dummy@localhost/some-other-resource", "info");
expect(converse.chatboxes.getChatBox).not.toHaveBeenCalled();
converse.filter_by_resource = false;
});
waits(50);
runs(function () {
message = "This message sent to a different resource will be shown";
msg = $msg({
from: sender_jid,
to: converse.bare_jid+'/'+"some-other-resource",
type: 'chat',
id: '134234623462346'
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
converse.chatboxes.onMessage(msg);
});
waits(50);
runs(function () {
expect(converse.chatboxes.getChatBox).toHaveBeenCalled();
var chatboxview = converse.chatboxviews.get(sender_jid);
var $chat_content = chatboxview.$el.find('.chat-content:last');
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
expect(msg_txt).toEqual(message);
});
}); });
it("is ignored if it's a malformed headline message", function () { it("is ignored if it's a malformed headline message", function () {
......
...@@ -259,6 +259,7 @@ ...@@ -259,6 +259,7 @@
csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out. csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
debug: false, debug: false,
expose_rid_and_sid: false, expose_rid_and_sid: false,
filter_by_resource: false,
forward_messages: false, forward_messages: false,
hide_offline_users: false, hide_offline_users: false,
include_offline_state: false, include_offline_state: false,
...@@ -1261,15 +1262,13 @@ ...@@ -1261,15 +1262,13 @@
to_jid = $message.attr('to'), to_jid = $message.attr('to'),
to_resource = Strophe.getResourceFromJid(to_jid); to_resource = Strophe.getResourceFromJid(to_jid);
if (to_resource && to_resource !== converse.resource) { if (converse.filter_by_resource && (to_resource && to_resource !== converse.resource)) {
converse.log( converse.log(
'onMessage: Ignoring incoming message intended for a different resource: '+to_jid, 'onMessage: Ignoring incoming message intended for a different resource: '+to_jid,
'info' 'info'
); );
return true; return true;
} else if (from_jid === converse.connection.jid) { } else if (from_jid === converse.connection.jid) {
// FIXME: Forwarded messages should be sent to specific
// resources, not broadcasted
converse.log( converse.log(
"onMessage: Ignoring incoming message sent from this client's JID: "+from_jid, "onMessage: Ignoring incoming message sent from this client's JID: "+from_jid,
'info' 'info'
......
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