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