From d1bf5b8466b82f559b97efa8b85136779cca59de Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 16 Dec 2013 19:19:25 +0200 Subject: [PATCH] Add event emitter tests for chatrooms. Updates #48 --- converse.js | 19 ++++++++++++------- spec/ChatRoomSpec.js | 31 +++++++++++++++++++++++++++++-- tests/mock.js | 3 ++- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/converse.js b/converse.js index fe85bbcf3..c677e4145 100644 --- a/converse.js +++ b/converse.js @@ -942,7 +942,6 @@ }, sendMessage: function (text) { - converse.emit('onMessageSend', text); var match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/), msgs; if (match) { if (match[1] === "clear") { @@ -995,6 +994,7 @@ } else { this.sendMessage(message); } + converse.emit('onMessageSend', message); } this.$el.data('composing', false); } else if (!this.model.get('chatroom')) { @@ -2241,12 +2241,17 @@ })); } if (!body) { return true; } - this.showMessage($chat_content, - {'message': body, - 'sender': sender === this.model.get('nick') && 'me' || 'room', - 'fullname': sender, - 'time': converse.toISOString(message_datetime) - }); + var display_sender = sender === this.model.get('nick') && 'me' || 'room'; + this.showMessage($chat_content, { + 'message': body, + 'sender': display_sender, + 'fullname': sender, + 'time': converse.toISOString(message_datetime) + }); + if (display_sender === 'room') { + // We only emit an event if it's not our own message + converse.emit('onMessage', message); + } return true; }, diff --git a/spec/ChatRoomSpec.js b/spec/ChatRoomSpec.js index 424b59713..b31fe8714 100644 --- a/spec/ChatRoomSpec.js +++ b/spec/ChatRoomSpec.js @@ -18,7 +18,6 @@ var chatroomview = this.chatboxesview.views['lounge@muc.localhost'], $participant_list; var roster = {}, room = {}, i; - for (i=0; i