From 4f227b467b4f08f9abac6ba1558271d96ee7236b Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 10 Jan 2018 12:45:12 +0000 Subject: [PATCH] Take all messages except chat events into consideration when determining where to insert new messages --- spec/chatbox.js | 4 ++-- spec/chatroom.js | 8 ++++---- src/converse-chatview.js | 12 ++++++------ src/templates/new_day.html | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/chatbox.js b/spec/chatbox.js index 05eb3a4a4..d6c195d00 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -1401,7 +1401,7 @@ var $time = $chat_content.find('time'); expect($time.length).toEqual(1); - expect($time.attr('class')).toEqual('chat-info chat-date'); + expect($time.attr('class')).toEqual('message chat-info chat-date'); expect($time.data('isodate')).toEqual(moment(one_day_ago.startOf('day')).format()); expect($time.text()).toEqual(moment(one_day_ago.startOf('day')).format("dddd MMM Do YYYY")); @@ -1421,7 +1421,7 @@ expect($time.length).toEqual(2); // There are now two time elements $time = $chat_content.find('time:last'); // We check the last one var message_date = new Date(); - expect($time.attr('class')).toEqual('chat-info chat-date'); + expect($time.attr('class')).toEqual('message chat-info chat-date'); expect($time.data('isodate')).toEqual(moment(message_date).startOf('day').format()); expect($time.text()).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY")); diff --git a/spec/chatroom.js b/spec/chatroom.js index 6b6970457..ac8a0ac06 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -639,7 +639,7 @@ var $time = $chat_content.find('time'); expect($time.length).toEqual(1); - expect($time.attr('class')).toEqual('chat-info chat-date'); + expect($time.attr('class')).toEqual('message chat-info chat-date'); expect($time.data('isodate')).toEqual(moment().startOf('day').format()); expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the room."); @@ -664,7 +664,7 @@ $time = $chat_content.find('time'); expect($time.length).toEqual(1); - expect($time.attr('class')).toEqual('chat-info chat-date'); + expect($time.attr('class')).toEqual('message chat-info chat-date'); expect($time.data('isodate')).toEqual(moment().startOf('day').format()); expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect($chat_content.find('div.chat-info').length).toBe(1); @@ -700,7 +700,7 @@ expect($time.length).toEqual(2); $time = $chat_content.find('time:eq(1)'); - expect($time.attr('class')).toEqual('chat-info chat-date'); + expect($time.attr('class')).toEqual('message chat-info chat-date'); expect($time.data('isodate')).toEqual(moment().startOf('day').format()); expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect($chat_content.find('div.chat-info').length).toBe(1); @@ -738,7 +738,7 @@ expect($time.length).toEqual(2); $time = $chat_content.find('time:eq(1)'); - expect($time.attr('class')).toEqual('chat-info chat-date'); + expect($time.attr('class')).toEqual('message chat-info chat-date'); expect($time.data('isodate')).toEqual(moment().startOf('day').format()); expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect($chat_content.find('div.chat-info').length).toBe(1); diff --git a/src/converse-chatview.js b/src/converse-chatview.js index af0319ef2..55393c70f 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -468,14 +468,14 @@ if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) { return most_recent_date; } - /* XXX: Besides .chat-message and .chat-date elements, there are also - * .chat-event elements. These are however temporary and - * removed once a new element is inserted into the chat - * area, so we don't query for them here, otherwise we get - * a null reference later upon element insertion. + /* XXX: We avoid .chat-event messages, since they are + * temporary and get removed once a new element is + * inserted into the chat area, so we don't query for + * them here, otherwise we get a null reference later + * upon element insertion. */ const msg_dates = _.invokeMap( - sizzle('.chat-message, .chat-date', this.content), + sizzle('.message:not(.chat-event)', this.content), Element.prototype.getAttribute, 'data-isodate' ) if (_.isObject(cutoff)) { diff --git a/src/templates/new_day.html b/src/templates/new_day.html index 1edf88641..d6193695f 100644 --- a/src/templates/new_day.html +++ b/src/templates/new_day.html @@ -1 +1 @@ - +