From 7eb6b13f1027c8a62d1ba1fcfc0181a70a7d2b36 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 2 May 2018 14:55:10 +0200 Subject: [PATCH] Don't mark /me messages are followup messages. --- css/converse.css | 8 ++++++-- css/inverse.css | 8 ++++++-- sass/_messages.scss | 4 ++++ spec/chatbox.js | 26 ++++++++++++++++++++++---- src/converse-chatview.js | 27 ++++++++++++--------------- 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/css/converse.css b/css/converse.css index 343fc3ab2..c2983751e 100644 --- a/css/converse.css +++ b/css/converse.css @@ -8433,8 +8433,12 @@ body.reset { #conversejs .message.chat-msg .chat-msg-heading .chat-msg-time { padding-left: 0.25em; color: #9d9d9d; } - #conversejs .message.chat-msg.chat-action .chat-msg-heading { - margin-top: 0; } + #conversejs .message.chat-msg.chat-action { + display: block; } + #conversejs .message.chat-msg.chat-action .chat-msg-heading { + float: left; + margin-top: 0; + padding-bottom: 0; } #conversejs .message.chat-msg.chat-msg-followup .chat-msg-heading, #conversejs .message.chat-msg.chat-msg-followup .avatar { display: none; } diff --git a/css/inverse.css b/css/inverse.css index 95a769a14..42ac645f6 100644 --- a/css/inverse.css +++ b/css/inverse.css @@ -8621,8 +8621,12 @@ body { #conversejs .message.chat-msg .chat-msg-heading .chat-msg-time { padding-left: 0.25em; color: #9d9d9d; } - #conversejs .message.chat-msg.chat-action .chat-msg-heading { - margin-top: 0; } + #conversejs .message.chat-msg.chat-action { + display: block; } + #conversejs .message.chat-msg.chat-action .chat-msg-heading { + float: left; + margin-top: 0; + padding-bottom: 0; } #conversejs .message.chat-msg.chat-msg-followup .chat-msg-heading, #conversejs .message.chat-msg.chat-msg-followup .avatar { display: none; } diff --git a/sass/_messages.scss b/sass/_messages.scss index add5be912..430869cd5 100644 --- a/sass/_messages.scss +++ b/sass/_messages.scss @@ -144,8 +144,12 @@ } } &.chat-action { + display: block; + .chat-msg-heading { + float: left; margin-top: 0; + padding-bottom: 0; } } &.chat-msg-followup { diff --git a/spec/chatbox.js b/spec/chatbox.js index b4e185192..842d5803d 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -58,11 +58,8 @@ var view; test_utils.createContacts(_converse, 'current'); test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp']) + .then(() => test_utils.waitUntil(() => _converse.xmppstatus.get('fullname')), 300) .then(function () { - return test_utils.waitUntil(function () { - return _converse.xmppstatus.get('fullname'); - }, 300); - }).then(function () { test_utils.openControlBox(); expect(_converse.chatboxes.length).toEqual(1); var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -81,14 +78,35 @@ test_utils.waitUntil(function () { return u.isVisible(view.el); }).then(function () { + expect(view.el.querySelectorAll('.chat-action').length).toBe(1); expect(_.includes(view.el.querySelector('.chat-msg-author').textContent, '**Max Frankfurter')).toBeTruthy(); expect($(view.el).find('.chat-msg-text').text()).toBe(' is tired'); message = '/me is as well'; test_utils.sendMessage(view, message); + expect(view.el.querySelectorAll('.chat-action').length).toBe(2); expect(_.includes($(view.el).find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy(); expect($(view.el).find('.chat-msg-text:last').text()).toBe(' is as well'); expect($(view.el).find('.chat-msg:last').hasClass('chat-msg-followup')).toBe(false); + + // Check that /me messages after a normal message don't + // get the 'chat-msg-followup' class. + message = 'This a normal message'; + test_utils.sendMessage(view, message); + let message_el = view.el.querySelector('.message:last-child'); + expect(u.hasClass('chat-msg-followup', message_el)).toBeFalsy(); + + message = '/me wrote a 3rd person message'; + test_utils.sendMessage(view, message); + message_el = view.el.querySelector('.message:last-child'); + expect(view.el.querySelectorAll('.chat-action').length).toBe(3); + expect($(view.el).find('.chat-msg-text:last').text()).toBe(' wrote a 3rd person message'); + expect($(view.el).find('.chat-msg-author:last').is(':visible')).toBeTruthy(); + expect(u.hasClass('chat-msg-followup', message_el)).toBeFalsy(); + + + message = 'This a normal message'; + done(); }); }); diff --git a/src/converse-chatview.js b/src/converse-chatview.js index a058046b5..23306dd70 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -683,25 +683,22 @@ */ const from = el.getAttribute('data-from'), previous_el = el.previousElementSibling, - date = moment(el.getAttribute('data-isodate')); - - if (previous_el.getAttribute('data-from') === from && - date.isBefore(moment(previous_el.getAttribute('data-isodate')).add(10, 'minutes'))) { + date = moment(el.getAttribute('data-isodate')), + next_el = el.nextElementSibling; + if (!u.hasClass('chat-action', el) && !u.hasClass('chat-action', previous_el) && + previous_el.getAttribute('data-from') === from && + date.isBefore(moment(previous_el.getAttribute('data-isodate')).add(10, 'minutes'))) { u.addClass('chat-msg-followup', el); } - const next_el = el.nextElementSibling; - if (!next_el) { - return; - } - if (next_el.getAttribute('data-from') !== from) { - u.removeClass('chat-msg-followup', next_el); + if (!next_el) { return; } + + if (!u.hasClass('chat-action', 'el') && + next_el.getAttribute('data-from') === from && + moment(next_el.getAttribute('data-isodate')).isBefore(date.add(10, 'minutes'))) { + u.addClass('chat-msg-followup', next_el); } else { - if (moment(next_el.getAttribute('data-isodate')).isBefore(date.add(10, 'minutes'))) { - u.addClass('chat-msg-followup', next_el); - } else { - u.removeClass('chat-msg-followup', next_el); - } + u.removeClass('chat-msg-followup', next_el); } },