فهرست منبع

Bugfix. show method must be debounced per instance

Otherwise it gets debounced for multiple instances and certain chat boxes will
then not get shown.
JC Brand 9 سال پیش
والد
کامیت
6eb08bd42f
1فایلهای تغییر یافته به همراه30 افزوده شده و 18 حذف شده
  1. 30 18
      src/converse-core.js

+ 30 - 18
src/converse-core.js

@@ -2252,26 +2252,38 @@
                 return this;
             },
 
-            show: _.debounce(function (focus) {
-                if (this.$el.is(':visible') && this.$el.css('opacity') === "1") {
-                    if (focus) { this.focus(); }
-                    return this;
+            show: function (focus) {
+                if (typeof this.debouncedShow === 'undefined') {
+                    /* We wrap the method in a debouncer and set it on the
+                     * instance, so that we have it debounced per instance.
+                     * Debouncing it on the class-level is too broad.
+                     */
+                    this.debouncedShow = _.debounce(function (focus) {
+                        if (this.$el.is(':visible') && this.$el.css('opacity') === "1") {
+                            if (focus) { this.focus(); }
+                            return this;
+                        }
+                        this.initDragResize().setDimensions();
+                        // We call trimChats before fading in, to avoid ugly transition
+                        // effects.
+                        converse.chatboxviews.trimChats(this);
+                        this.$el.fadeIn(function () {
+                            if (converse.connection.connected) {
+                                // Without a connection, we haven't yet initialized
+                                // localstorage
+                                this.model.save();
+                            }
+                            this.setChatState(converse.ACTIVE);
+                            this.scrollDown();
+                            if (focus) {
+                                this.focus();
+                            }
+                        }.bind(this));
+                    }, 250, true);
                 }
-                this.initDragResize().setDimensions();
-                this.$el.fadeIn(function () {
-                    if (converse.connection.connected) {
-                        // Without a connection, we haven't yet initialized
-                        // localstorage
-                        this.model.save();
-                    }
-                    this.setChatState(converse.ACTIVE);
-                    this.scrollDown();
-                    if (focus) {
-                        this.focus();
-                    }
-                }.bind(this));
+                this.debouncedShow.apply(this, arguments);
                 return this;
-            }, 250, true),
+            },
 
             scrollDownMessageHeight: function ($message) {
                 if (this.$content.is(':visible')) {