فهرست منبع

Bugfix. Don't remove model, simply remove view

Otherwise the model gets removed mid-creation, which causes the
`url required` error from Backbone.
JC Brand 7 سال پیش
والد
کامیت
776f49d5c3
3فایلهای تغییر یافته به همراه19 افزوده شده و 8 حذف شده
  1. 7 5
      src/converse-chatboxes.js
  2. 0 3
      src/converse-message-view.js
  3. 12 0
      src/utils/core.js

+ 7 - 5
src/converse-chatboxes.js

@@ -115,10 +115,7 @@
                 },
                 },
 
 
                 isOnlyChatStateNotification () {
                 isOnlyChatStateNotification () {
-                    return this.get('chat_state') &&
-                            !this.get('oob_url') &&
-                            !this.get('file') &&
-                            !this.get('message');
+                    return u.isOnlyChatStateNotification(this);
                 },
                 },
 
 
                 getDisplayName () {
                 getDisplayName () {
@@ -451,7 +448,12 @@
                     /* Create a Backbone.Message object inside this chat box
                     /* Create a Backbone.Message object inside this chat box
                      * based on the identified message stanza.
                      * based on the identified message stanza.
                      */
                      */
-                    return this.messages.create(this.getMessageAttributesFromStanza.apply(this, arguments));
+                    const attrs = this.getMessageAttributesFromStanza.apply(this, arguments)
+                    if (u.isOnlyChatStateNotification(attrs)) {
+                        return;
+                    } else {
+                        return this.messages.create(attrs);
+                    }
                 },
                 },
 
 
                 newMessageWillBeHidden () {
                 newMessageWillBeHidden () {

+ 0 - 3
src/converse-message-view.js

@@ -160,9 +160,6 @@
                 },
                 },
 
 
                 renderChatStateNotification () {
                 renderChatStateNotification () {
-                    if (this.model.get('delayed')) {
-                        return this.model.destroy();
-                    }
                     let text;
                     let text;
                     const from = this.model.get('from'),
                     const from = this.model.get('from'),
                           name = this.model.getDisplayName();
                           name = this.model.getDisplayName();

+ 12 - 0
src/utils/core.js

@@ -13,6 +13,7 @@
             "sizzle",
             "sizzle",
             "es6-promise",
             "es6-promise",
             "lodash.noconflict",
             "lodash.noconflict",
+            "backbone",
             "strophe",
             "strophe",
             "uri",
             "uri",
             "tpl!audio",
             "tpl!audio",
@@ -46,6 +47,7 @@
         sizzle,
         sizzle,
         Promise,
         Promise,
         _,
         _,
+        Backbone,
         Strophe,
         Strophe,
         URI,
         URI,
         tpl_audio,
         tpl_audio,
@@ -488,6 +490,16 @@
         }
         }
     };
     };
 
 
+    u.isOnlyChatStateNotification = function (attrs) {
+        if (attrs instanceof Backbone.Model) {
+            attrs = attrs.attributes;
+        }
+        return attrs['chat_state'] &&
+            !attrs['oob_url'] &&
+            !attrs['file'] &&
+            !attrs['message'];
+    };
+
     u.isOTRMessage = function (message) {
     u.isOTRMessage = function (message) {
         var body = message.querySelector('body'),
         var body = message.querySelector('body'),
             text = (!_.isNull(body) ? body.textContent: undefined);
             text = (!_.isNull(body) ? body.textContent: undefined);