diff --git a/spec/chatbox.js b/spec/chatbox.js index 640a4a1b7..0d072e835 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -16,6 +16,32 @@ return describe("Chatboxes", function() { describe("A Chatbox", function () { + it("supports the /me command", mock.initConverse(function (_converse) { + test_utils.createContacts(_converse, 'current'); + test_utils.openControlBox(); + test_utils.openContactsPanel(_converse); + expect(_converse.chatboxes.length).toEqual(1); + var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; + var message = '/me is tired'; + var msg = $msg({ + from: sender_jid, + to: _converse.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('body').t(message).up() + .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); + + _converse.chatboxes.onMessage(msg); + var view = _converse.chatboxviews.get(sender_jid); + expect(_.includes(view.$el.find('.chat-msg-author').text(), '**Max Frankfurter')).toBeTruthy(); + expect(view.$el.find('.chat-msg-content').text()).toBe(' is tired'); + + message = '/me is as well'; + test_utils.sendMessage(view, message); + expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy(); + expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well'); + })); + it("is created when you click on a roster item", mock.initConverse(function (_converse) { test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); diff --git a/spec/chatroom.js b/spec/chatroom.js index af969b18c..33bffa887 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -362,6 +362,35 @@ expect(view.$el.find('.chat-message').hasClass('mentioned')).toBeTruthy(); })); + it("supports the /me command", mock.initConverse(function (_converse) { + test_utils.createContacts(_converse, 'current'); + test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); + var view = _converse.chatboxviews.get('lounge@localhost'); + if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } + var message = '/me is tired'; + var nick = mock.chatroom_names[0], + msg = $msg({ + from: 'lounge@localhost/'+nick, + id: (new Date()).getTime(), + to: 'dummy@localhost', + type: 'groupchat' + }).c('body').t(message).tree(); + _converse.chatboxes.onMessage(msg); + expect(_.includes(view.$el.find('.chat-msg-author').text(), '**Dyon van de Wege')).toBeTruthy(); + expect(view.$el.find('.chat-msg-content').text()).toBe(' is tired'); + + message = '/me is as well'; + msg = $msg({ + from: 'lounge@localhost/dummy', + id: (new Date()).getTime(), + to: 'dummy@localhost', + type: 'groupchat' + }).c('body').t(message).tree(); + _converse.chatboxes.onMessage(msg); + expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy(); + expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well'); + })); + it("can have spaces and special characters in its name", mock.initConverse(function (_converse) { test_utils.openChatRoom(_converse, 'lounge & leisure', 'localhost', 'dummy'); var view = _converse.chatboxviews.get( diff --git a/src/converse-chatview.js b/src/converse-chatview.js index 62988d7d0..73d0f9e2e 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -325,8 +325,12 @@ if ((match) && (match[1] === 'me')) { text = text.replace(/^\/me/, ''); template = _converse.templates.action; - fullname = _converse.xmppstatus.get('fullname'); - username = _.isNil(fullname)? _converse.bare_jid: fullname; + if (attrs.sender === 'me') { + fullname = _converse.xmppstatus.get('fullname'); + username = _.isNil(fullname)? _converse.bare_jid: fullname; + } else { + username = attrs.fullname; + } } else { template = _converse.templates.message; username = attrs.sender === 'me' && __('me') || fullname;