Răsfoiți Sursa

Bugfix. Don't scroll down on archived messages

when already scrolled up.
JC Brand 8 ani în urmă
părinte
comite
e1dace59ae
2 a modificat fișierele cu 14 adăugiri și 8 ștergeri
  1. 5 5
      src/converse-chatview.js
  2. 9 3
      src/utils.js

+ 5 - 5
src/converse-chatview.js

@@ -419,16 +419,16 @@
 
                 handleTextMessage: function (message) {
                     this.showMessage(_.clone(message.attributes));
-                    if (message.get('sender') !== 'me') {
-                        if (!message.get('archive_id') && this.model.get('scrolled', true)) {
-                            this.$el.find('.new-msgs-indicator').removeClass('hidden');
-                        }
-                    } else {
+                    if (utils.isNewMessage(message) && message.get('sender') === 'me') {
                         // We remove the "scrolled" flag so that the chat area
                         // gets scrolled down. We always want to scroll down
                         // when the user writes a message as opposed to when a
                         // message is received.
                         this.model.set('scrolled', false);
+                    } else {
+                        if (utils.isNewMessage(message) && this.model.get('scrolled', true)) {
+                            this.$el.find('.new-msgs-indicator').removeClass('hidden');
+                        }
                     }
                     if (this.shouldShowOnTextMessage()) {
                         this.show();

+ 9 - 3
src/utils.js

@@ -18,7 +18,9 @@
         "tpl!form_captcha"
     ], factory);
 }(this, function (
-        $, sizzle, dummy, _, locales, moment,
+        $, sizzle, dummy, _,
+        locales,
+        moment,
         Strophe,
         tpl_field,
         tpl_select_option,
@@ -225,11 +227,15 @@
             }
         },
 
-        isNewMessage: function (stanza) {
+        isNewMessage: function (message) {
             /* Given a stanza, determine whether it's a new
              * message, i.e. not a MAM archived one.
              */
-            return !(sizzle('result[xmlns="'+Strophe.NS.MAM+'"]', stanza).length);
+            if (message instanceof Element) {
+                return !(sizzle('result[xmlns="'+Strophe.NS.MAM+'"]', message).length);
+            } else {
+                return !message.get('archive_id');
+            }
         },
 
         isOTRMessage: function (message) {