Commit 25cc2290 authored by JC Brand's avatar JC Brand

Refactor message handling

- use the same method for both normal and OTR messages
- fix /me actions for OTR messages
- rename messaging methods to minimize ambiguity

Conflicts:
	converse.js
	tests/utils.js
parent c38e4f1c
This diff is collapsed.
...@@ -4,7 +4,9 @@ Changelog ...@@ -4,7 +4,9 @@ Changelog
0.7.3 (Unreleased) 0.7.3 (Unreleased)
------------------ ------------------
* #125 Fix crypto dependencies [jcbrand] * #125 Bugfix: crypto dependencies loaded in wrong order [jcbrand]
* Bugfix: action messages (i.e. /me) didn't work in OTR mode. [jcbrand]
0.7.3 (2014-02-23) 0.7.3 (2014-02-23)
------------------ ------------------
......
...@@ -216,6 +216,15 @@ ...@@ -216,6 +216,15 @@
}, converse)); }, converse));
describe("A Chat Message", $.proxy(function () { describe("A Chat Message", $.proxy(function () {
beforeEach(function () {
runs(function () {
utils.closeAllChatBoxes();
});
waits(250);
runs(function () {});
});
it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () { it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var message = 'This is a received message'; var message = 'This is a received message';
...@@ -232,9 +241,8 @@ ...@@ -232,9 +241,8 @@
expect(this.chatboxes.get(sender_jid)).not.toBeDefined(); expect(this.chatboxes.get(sender_jid)).not.toBeDefined();
runs($.proxy(function () { runs($.proxy(function () {
// messageReceived is a handler for received XMPP // onMessage is a handler for received XMPP messages
// messages this.chatboxes.onMessage(msg);
this.chatboxes.messageReceived(msg);
expect(converse.emit).toHaveBeenCalledWith('onMessage', msg); expect(converse.emit).toHaveBeenCalledWith('onMessage', msg);
}, converse)); }, converse));
waits(300); waits(300);
...@@ -288,7 +296,7 @@ ...@@ -288,7 +296,7 @@
}).c('body').t(message).up() }).c('body').t(message).up()
.c('delay', { xmlns:'urn:xmpp:delay', from: 'localhost', stamp: converse.toISOString(one_day_ago) }) .c('delay', { xmlns:'urn:xmpp:delay', from: 'localhost', stamp: converse.toISOString(one_day_ago) })
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
this.chatboxes.messageReceived(msg); this.chatboxes.onMessage(msg);
expect(converse.emit).toHaveBeenCalledWith('onMessage', msg); expect(converse.emit).toHaveBeenCalledWith('onMessage', msg);
expect(chatbox.messages.length).toEqual(1); expect(chatbox.messages.length).toEqual(1);
msg_obj = chatbox.messages.models[0]; msg_obj = chatbox.messages.models[0];
...@@ -309,7 +317,7 @@ ...@@ -309,7 +317,7 @@
id: new Date().getTime() id: new Date().getTime()
}).c('body').t(message).up() }).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
this.chatboxes.messageReceived(msg); this.chatboxes.onMessage(msg);
expect(converse.emit).toHaveBeenCalledWith('onMessage', msg); expect(converse.emit).toHaveBeenCalledWith('onMessage', msg);
// Check that there is a <time> element, with the required // Check that there is a <time> element, with the required
// props. // props.
...@@ -414,7 +422,7 @@ ...@@ -414,7 +422,7 @@
id: (new Date()).getTime() id: (new Date()).getTime()
}).c('body').t(message).up() }).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
this.chatboxes.messageReceived(msg); this.chatboxes.onMessage(msg);
expect(converse.incrementMsgCounter).toHaveBeenCalled(); expect(converse.incrementMsgCounter).toHaveBeenCalled();
expect(this.msg_counter).toBe(1); expect(this.msg_counter).toBe(1);
expect(converse.emit).toHaveBeenCalledWith('onMessage', msg); expect(converse.emit).toHaveBeenCalledWith('onMessage', msg);
...@@ -444,7 +452,7 @@ ...@@ -444,7 +452,7 @@
id: (new Date()).getTime() id: (new Date()).getTime()
}).c('body').t(message).up() }).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
this.chatboxes.messageReceived(msg); this.chatboxes.onMessage(msg);
expect(converse.incrementMsgCounter).not.toHaveBeenCalled(); expect(converse.incrementMsgCounter).not.toHaveBeenCalled();
expect(this.msg_counter).toBe(0); expect(this.msg_counter).toBe(0);
}, converse)); }, converse));
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
}; };
utils.openChatBoxFor = function (jid) { utils.openChatBoxFor = function (jid) {
converse.rosterview.rosteritemviews[jid].openChat(mock.event); return converse.rosterview.rosteritemviews[jid].openChat(mock.event);
}; };
utils.clearChatBoxMessages = function (jid) { utils.clearChatBoxMessages = function (jid) {
......
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