Skip to content

Commit

Permalink
minimize: Don't trim chats prematurely.
Browse files Browse the repository at this point in the history
Also, the minimized chats view now gets rendered after chat boxes are fetched,
so we need to make it check for already added and minimized chats.
  • Loading branch information
jcbrand committed Aug 29, 2017
1 parent b9b9689 commit e6e0fc9
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/converse-minimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
// fullscreen. In this case we don't trim.
return;
}
_converse.api.waitUntil('chatBoxesInitialized').then(() => {
_converse.api.waitUntil('minimizedChatsInitialized').then(() => {
const $minimized = _.get(_converse.minimized_chats, '$el'),
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null;
Expand Down Expand Up @@ -383,12 +383,27 @@
initialize () {
this.render();
this.initToggle();
this.addMultipleChats(this.model.where({'minimized': true}));
this.model.on("add", this.onChanged, this);
this.model.on("destroy", this.removeChat, this);
this.model.on("change:minimized", this.onChanged, this);
this.model.on('change:num_unread', this.updateUnreadMessagesCounter, this);
},

render () {
if (!this.el.parentElement) {
this.el.innerHTML = tpl_chats_panel();
_converse.chatboxviews.el.appendChild(this.el);
}
if (this.keys().length === 0) {
this.el.classList.add('hidden');
} else if (this.keys().length > 0 && !this.$el.is(':visible')) {
this.el.classList.remove('hidden');
_converse.chatboxviews.trimChats();
}
return this.$el;
},

tearDown () {
this.model.off("add", this.onChanged);
this.model.off("destroy", this.removeChat);
Expand All @@ -407,21 +422,6 @@
this.toggleview.model.fetch();
},

render () {
if (!this.el.parentElement) {
this.el.innerHTML = tpl_chats_panel();
_converse.chatboxviews.el.appendChild(this.el);
}
if (this.keys().length === 0) {
this.el.classList.add('hidden');
_converse.chatboxviews.trimChats.bind(_converse.chatboxviews);
} else if (this.keys().length > 0 && !this.$el.is(':visible')) {
this.el.classList.remove('hidden');
_converse.chatboxviews.trimChats();
}
return this.$el;
},

toggle (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')});
Expand All @@ -440,6 +440,20 @@
}
},

addMultipleChats (items) {
_.each(items, (item) => {
const existing = this.get(item.get('id'));
if (existing && existing.$el.parent().length !== 0) {
return;
}
const view = new _converse.MinimizedChatBoxView({model: item});
this.$('.minimized-chats-flyout').append(view.render());
this.add(item.get('id'), view);
});
this.toggleview.model.set({'num_minimized': this.keys().length});
this.render();
},

addChat (item) {
const existing = this.get(item.get('id'));
if (existing && existing.$el.parent().length !== 0) {
Expand Down

0 comments on commit e6e0fc9

Please sign in to comment.