Selaa lähdekoodia

Ignore (and destroy) archived/delayed messages with no body to show

JC Brand 6 vuotta sitten
vanhempi
commit
1ca7d34c25
3 muutettua tiedostoa jossa 36 lisäystä ja 23 poistoa
  1. 19 10
      dist/converse.js
  2. 5 8
      src/converse-chatview.js
  3. 12 5
      src/headless/utils/core.js

+ 19 - 10
dist/converse.js

@@ -49913,18 +49913,17 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
          * Parameters:
          *  (Backbone.Model) message: The message object
          */
+        if (!_converse_headless_utils_emoji__WEBPACK_IMPORTED_MODULE_21__["default"].isNewMessage(message) && _converse_headless_utils_emoji__WEBPACK_IMPORTED_MODULE_21__["default"].isEmptyMessage(message)) {
+          // Handle archived or delayed messages without any message
+          // text to show.
+          return message.destroy();
+        }
+
         const view = new _converse.MessageView({
           'model': message
         });
         await view.render();
         this.clearChatStateNotification(message);
-
-        if (!view.el.innerHTML) {
-          // An "inactive" CSN message (for example) will have an
-          // empty body. No need to then continue.
-          return _converse.log("Not inserting a message with empty element", Strophe.LogLevel.INFO);
-        }
-
         this.insertMessage(view);
         this.insertDayIndicator(view.el);
         this.setScrollPosition(view.el);
@@ -69675,9 +69674,19 @@ u.isNewMessage = function (message) {
    */
   if (message instanceof Element) {
     return !(sizzle__WEBPACK_IMPORTED_MODULE_4___default()(`result[xmlns="${strophe_js__WEBPACK_IMPORTED_MODULE_2__["Strophe"].NS.MAM}"]`, message).length && sizzle__WEBPACK_IMPORTED_MODULE_4___default()(`delay[xmlns="${strophe_js__WEBPACK_IMPORTED_MODULE_2__["Strophe"].NS.DELAY}"]`, message).length);
-  } else {
-    return !(message.get('is_delayed') && message.get('is_archived'));
+  } else if (message instanceof backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model) {
+    message = message.attributes;
   }
+
+  return !(message['is_delayed'] && message['is_archived']);
+};
+
+u.isEmptyMessage = function (attrs) {
+  if (attrs instanceof backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model) {
+    attrs = attrs.attributes;
+  }
+
+  return !attrs['oob_url'] && !attrs['file'] && !(attrs['is_encrypted'] && attrs['plaintext']) && !attrs['message'];
 };
 
 u.isOnlyChatStateNotification = function (attrs) {
@@ -69685,7 +69694,7 @@ u.isOnlyChatStateNotification = function (attrs) {
     attrs = attrs.attributes;
   }
 
-  return attrs['chat_state'] && !attrs['oob_url'] && !attrs['file'] && !(attrs['is_encrypted'] && attrs['plaintext']) && !attrs['message'];
+  return attrs['chat_state'] && u.isEmptyMessage(attrs);
 };
 
 u.isHeadlineMessage = function (_converse, message) {

+ 5 - 8
src/converse-chatview.js

@@ -751,17 +751,14 @@ converse.plugins.add('converse-chatview', {
                  * Parameters:
                  *  (Backbone.Model) message: The message object
                  */
+                if (!u.isNewMessage(message) && u.isEmptyMessage(message)) {
+                    // Handle archived or delayed messages without any message
+                    // text to show.
+                    return message.destroy();
+                }
                 const view = new _converse.MessageView({'model': message});
                 await view.render();
                 this.clearChatStateNotification(message);
-                if (!view.el.innerHTML) {
-                    // An "inactive" CSN message (for example) will have an
-                    // empty body. No need to then continue.
-                    return _converse.log(
-                        "Not inserting a message with empty element",
-                        Strophe.LogLevel.INFO
-                    );
-                }
                 this.insertMessage(view);
                 this.insertDayIndicator(view.el);
                 this.setScrollPosition(view.el);

+ 12 - 5
src/headless/utils/core.js

@@ -71,22 +71,29 @@ u.isNewMessage = function (message) {
             sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, message).length &&
             sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, message).length
         );
-    } else {
-        return !(message.get('is_delayed') && message.get('is_archived'));
+    } else if (message instanceof Backbone.Model) {
+        message = message.attributes;
     }
+    return !(message['is_delayed'] && message['is_archived']);
 };
 
-u.isOnlyChatStateNotification = function (attrs) {
+u.isEmptyMessage = function (attrs) {
     if (attrs instanceof Backbone.Model) {
         attrs = attrs.attributes;
     }
-    return attrs['chat_state'] &&
-        !attrs['oob_url'] &&
+    return !attrs['oob_url'] &&
         !attrs['file'] &&
         !(attrs['is_encrypted'] && attrs['plaintext']) &&
         !attrs['message'];
 };
 
+u.isOnlyChatStateNotification = function (attrs) {
+    if (attrs instanceof Backbone.Model) {
+        attrs = attrs.attributes;
+    }
+    return attrs['chat_state'] && u.isEmptyMessage(attrs);
+};
+
 u.isHeadlineMessage = function (_converse, message) {
     const from_jid = message.getAttribute('from');
     if (message.getAttribute('type') === 'headline') {