Browse Source

Take all messages except chat events into consideration

when determining where to insert new messages
JC Brand 7 năm trước cách đây
mục cha
commit
4f227b467b

+ 2 - 2
spec/chatbox.js

@@ -1401,7 +1401,7 @@
 
 
                         var $time = $chat_content.find('time');
                         var $time = $chat_content.find('time');
                         expect($time.length).toEqual(1);
                         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.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"));
                         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
                         expect($time.length).toEqual(2); // There are now two time elements
                         $time = $chat_content.find('time:last'); // We check the last one
                         $time = $chat_content.find('time:last'); // We check the last one
                         var message_date = new Date();
                         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.data('isodate')).toEqual(moment(message_date).startOf('day').format());
                         expect($time.text()).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY"));
                         expect($time.text()).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY"));
 
 

+ 4 - 4
spec/chatroom.js

@@ -639,7 +639,7 @@
 
 
                 var $time = $chat_content.find('time');
                 var $time = $chat_content.find('time');
                 expect($time.length).toEqual(1);
                 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.data('isodate')).toEqual(moment().startOf('day').format());
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 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.");
                 expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the room.");
@@ -664,7 +664,7 @@
 
 
                 $time = $chat_content.find('time');
                 $time = $chat_content.find('time');
                 expect($time.length).toEqual(1);
                 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.data('isodate')).toEqual(moment().startOf('day').format());
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 expect($chat_content.find('div.chat-info').length).toBe(1);
                 expect($chat_content.find('div.chat-info').length).toBe(1);
@@ -700,7 +700,7 @@
                 expect($time.length).toEqual(2);
                 expect($time.length).toEqual(2);
 
 
                 $time = $chat_content.find('time:eq(1)');
                 $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.data('isodate')).toEqual(moment().startOf('day').format());
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 expect($chat_content.find('div.chat-info').length).toBe(1);
                 expect($chat_content.find('div.chat-info').length).toBe(1);
@@ -738,7 +738,7 @@
                 expect($time.length).toEqual(2);
                 expect($time.length).toEqual(2);
 
 
                 $time = $chat_content.find('time:eq(1)');
                 $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.data('isodate')).toEqual(moment().startOf('day').format());
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 expect($time.text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
                 expect($chat_content.find('div.chat-info').length).toBe(1);
                 expect($chat_content.find('div.chat-info').length).toBe(1);

+ 6 - 6
src/converse-chatview.js

@@ -468,14 +468,14 @@
                     if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) {
                     if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) {
                         return most_recent_date;
                         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(
                     const msg_dates = _.invokeMap(
-                        sizzle('.chat-message, .chat-date', this.content),
+                        sizzle('.message:not(.chat-event)', this.content),
                         Element.prototype.getAttribute, 'data-isodate'
                         Element.prototype.getAttribute, 'data-isodate'
                     )
                     )
                     if (_.isObject(cutoff)) {
                     if (_.isObject(cutoff)) {

+ 1 - 1
src/templates/new_day.html

@@ -1 +1 @@
-<time class="chat-info chat-date" data-isodate="{{{o.isodate}}}">{{{o.datestring}}}</time>
+<time class="message chat-info chat-date" data-isodate="{{{o.isodate}}}">{{{o.datestring}}}</time>