New test and fixes to the message handler. updates #431
This commit is contained in:
parent
7703b9b33c
commit
c2ccb2c693
20
converse.js
20
converse.js
@ -3285,21 +3285,18 @@
|
||||
/* Handler method for all incoming single-user chat "message" stanzas.
|
||||
*/
|
||||
var $message = $(message),
|
||||
contact_jid, $forwarded, $received, $sent,
|
||||
contact_jid, $forwarded, $received, $sent, from_bare_jid, from_resource, is_me,
|
||||
msgid = $message.attr('id'),
|
||||
chatbox, resource, roster_item,
|
||||
message_from = $message.attr('from'),
|
||||
from_bare_jid = Strophe.getBareJidFromJid(message_from),
|
||||
from_resource = Strophe.getResourceFromJid(message_from),
|
||||
from_jid = $message.attr('from'),
|
||||
to_jid = $message.attr('to'),
|
||||
to_resource = Strophe.getResourceFromJid(to_jid),
|
||||
is_me = from_bare_jid == converse.bare_jid;
|
||||
to_resource = Strophe.getResourceFromJid(to_jid);
|
||||
|
||||
if (to_resource && to_resource !== converse.resource) {
|
||||
converse.log('Ignore incoming message intended for a different resource: '+from_jid, 'info');
|
||||
converse.log('Ignore incoming message intended for a different resource: '+to_jid, 'info');
|
||||
return true;
|
||||
}
|
||||
if (message_from === converse.connection.jid) {
|
||||
if (from_jid === converse.connection.jid) {
|
||||
// FIXME: Forwarded messages should be sent to specific resources, not broadcasted
|
||||
converse.log("Ignore incoming message sent from this client's JID: "+from_jid, 'info');
|
||||
return true;
|
||||
@ -3312,11 +3309,14 @@
|
||||
$message = $forwarded.children('message');
|
||||
} else if ($received.length) {
|
||||
$message = $received.children('forwarded').children('message');
|
||||
message_from = $message.attr('from');
|
||||
from_jid = $message.attr('from');
|
||||
} else if ($sent.length) {
|
||||
$message = $sent.children('forwarded').children('message');
|
||||
message_from = $message.attr('from');
|
||||
from_jid = $message.attr('from');
|
||||
}
|
||||
from_bare_jid = Strophe.getBareJidFromJid(from_jid);
|
||||
from_resource = Strophe.getResourceFromJid(from_jid);
|
||||
is_me = from_bare_jid == converse.bare_jid;
|
||||
|
||||
if (is_me) {
|
||||
// I am the sender, so this must be a forwarded message...
|
||||
|
@ -439,8 +439,7 @@
|
||||
var chatboxview = this.chatboxviews.get(sender_jid);
|
||||
expect(chatbox).toBeDefined();
|
||||
expect(chatboxview).toBeDefined();
|
||||
// Check that the message was received and check the
|
||||
// message parameters
|
||||
// Check that the message was received and check the message parameters
|
||||
expect(chatbox.messages.length).toEqual(1);
|
||||
var msg_obj = chatbox.messages.models[0];
|
||||
expect(msg_obj.get('message')).toEqual(message);
|
||||
@ -449,8 +448,7 @@
|
||||
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[0].split(' ')[0]);
|
||||
expect(msg_obj.get('sender')).toEqual('them');
|
||||
expect(msg_obj.get('delayed')).toEqual(false);
|
||||
// Now check that the message appears inside the
|
||||
// chatbox in the DOM
|
||||
// Now check that the message appears inside the chatbox in the DOM
|
||||
var $chat_content = chatboxview.$el.find('.chat-content');
|
||||
var msg_txt = $chat_content.find('.chat-message').find('.chat-message-content').text();
|
||||
expect(msg_txt).toEqual(message);
|
||||
@ -459,6 +457,22 @@
|
||||
}, converse));
|
||||
}, converse));
|
||||
|
||||
it("is ignored if it's intended for a different resource", function () {
|
||||
// Send a message from a different resource
|
||||
spyOn(converse, 'log');
|
||||
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||
var msg = $msg({
|
||||
from: sender_jid,
|
||||
to: converse.bare_jid+'/'+"some-other-resource",
|
||||
type: 'chat',
|
||||
id: (new Date()).getTime()
|
||||
}).c('body').t("This message will not be shown").up()
|
||||
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
||||
converse.chatboxes.onMessage(msg);
|
||||
expect(converse.log).toHaveBeenCalledWith(
|
||||
"Ignore incoming message intended for a different resource: dummy@localhost/some-other-resource", "info");
|
||||
});
|
||||
|
||||
it("received for a minimized chat box will increment a counter on its header", $.proxy(function () {
|
||||
var contact_name = mock.cur_names[0];
|
||||
var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||
|
Loading…
Reference in New Issue
Block a user