Commit e6e0fc90 authored by JC Brand's avatar JC Brand

minimize: Don't trim chats prematurely.

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.
parent b9b96896
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
// fullscreen. In this case we don't trim. // fullscreen. In this case we don't trim.
return; return;
} }
_converse.api.waitUntil('chatBoxesInitialized').then(() => { _converse.api.waitUntil('minimizedChatsInitialized').then(() => {
const $minimized = _.get(_converse.minimized_chats, '$el'), const $minimized = _.get(_converse.minimized_chats, '$el'),
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0, minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null; new_id = newchat ? newchat.model.get('id') : null;
...@@ -383,12 +383,27 @@ ...@@ -383,12 +383,27 @@
initialize () { initialize () {
this.render(); this.render();
this.initToggle(); this.initToggle();
this.addMultipleChats(this.model.where({'minimized': true}));
this.model.on("add", this.onChanged, this); this.model.on("add", this.onChanged, this);
this.model.on("destroy", this.removeChat, this); this.model.on("destroy", this.removeChat, this);
this.model.on("change:minimized", this.onChanged, this); this.model.on("change:minimized", this.onChanged, this);
this.model.on('change:num_unread', this.updateUnreadMessagesCounter, 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 () { tearDown () {
this.model.off("add", this.onChanged); this.model.off("add", this.onChanged);
this.model.off("destroy", this.removeChat); this.model.off("destroy", this.removeChat);
...@@ -407,21 +422,6 @@ ...@@ -407,21 +422,6 @@
this.toggleview.model.fetch(); 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) { toggle (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); } if (ev && ev.preventDefault) { ev.preventDefault(); }
this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')}); this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')});
...@@ -440,6 +440,20 @@ ...@@ -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) { addChat (item) {
const existing = this.get(item.get('id')); const existing = this.get(item.get('id'));
if (existing && existing.$el.parent().length !== 0) { if (existing && existing.$el.parent().length !== 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment