Fixes to trimming of chats.

- Don't trim if not connected.
- Move trimChats call to converse-minimized
- Immediately hide view to avoid race conditions.
This commit is contained in:
JC Brand 2016-03-28 14:52:00 +00:00
parent 8f601e8c94
commit 2869485c1e
2 changed files with 36 additions and 16 deletions

View File

@ -827,6 +827,19 @@
return this;
},
afterShown: 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();
}
},
show: function (focus) {
if (typeof this.debouncedShow === 'undefined') {
/* We wrap the method in a debouncer and set it on the
@ -839,19 +852,7 @@
return;
}
this.initDragResize().setDimensions();
this.$el.fadeIn(function () {
if (converse.connection.connected) {
// Without a connection, we haven't yet initialized
// localstorage
this.model.save();
}
converse.chatboxviews.trimChats(this);
this.setChatState(converse.ACTIVE);
this.scrollDown();
if (focus) {
this.focus();
}
}.bind(this));
this.$el.fadeIn(this.afterShown.bind(this));
}, 250, true);
}
this.debouncedShow.apply(this, arguments);

View File

@ -52,7 +52,9 @@
this._super.registerGlobalEventHandlers.apply(this, arguments);
$(window).on("resize", _.debounce(function (ev) {
converse.chatboxviews.trimChats();
if (converse.connection.connected) {
converse.chatboxviews.trimChats();
}
}, 200));
},
@ -104,6 +106,13 @@
return this._super.initialize.apply(this, arguments);
},
afterShown: function () {
this._super.afterShown.apply(this, arguments);
if (!this.model.get('minimized')) {
converse.chatboxviews.trimChats(this);
}
},
shouldShowOnTextMessage: function () {
return !this.model.get('minimized') &&
this._super.shouldShowOnTextMessage.apply(this, arguments);
@ -199,7 +208,7 @@
if (converse.no_trimming || (this.model.length <= 1)) {
return;
}
var oldest_chat, boxes_width,
var oldest_chat, boxes_width, view,
$minimized = converse.minimized_chats.$el,
minimized_width = _.contains(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null;
@ -211,6 +220,14 @@
if ((minimized_width + boxes_width) > $('body').outerWidth(true)) {
oldest_chat = this.getOldestMaximizedChat([new_id]);
if (oldest_chat) {
// We hide the chat immediately, because waiting
// for the event to fire (and letting the
// ChatBoxView hide it then) causes race
// conditions.
view = this.get(oldest_chat.get('id'));
if (view) {
view.$el.hide();
}
oldest_chat.minimize();
}
}
@ -434,7 +451,9 @@
converse.on('controlBoxOpened', function (evt, chatbox) {
// Wrapped in anon method because at scan time, chatboxviews
// attr not set yet.
converse.chatboxviews.trimChats(chatbox);
if (converse.connection.connected) {
converse.chatboxviews.trimChats(chatbox);
}
});
}
});