Commit 2d507c68 authored by JC Brand's avatar JC Brand

Always debounce trimChats

parent 1ef29bee
...@@ -284,7 +284,7 @@ converse.plugins.add('converse-minimize', { ...@@ -284,7 +284,7 @@ converse.plugins.add('converse-minimize', {
); );
}, },
async trimChats (newchat) { trimChats: _.debounce(async function (newchat) {
/* This method is called when a newly created chat box will /* This method is called when a newly created chat box will
* be shown. * be shown.
* *
...@@ -292,9 +292,11 @@ converse.plugins.add('converse-minimize', { ...@@ -292,9 +292,11 @@ converse.plugins.add('converse-minimize', {
* another chat box. Otherwise it minimizes the oldest chat box * another chat box. Otherwise it minimizes the oldest chat box
* to create space. * to create space.
*/ */
const { _converse } = this.__super__, if (!_converse.connection.connected || _converse.view_mode !== 'overlayed') {
shown_chats = this.getShownChats(), return;
body_width = u.getOuterWidth(document.querySelector('body'), true); }
const shown_chats = this.getShownChats();
const body_width = u.getOuterWidth(document.querySelector('body'), true);
if (_converse.no_trimming || shown_chats.length <= 1) { if (_converse.no_trimming || shown_chats.length <= 1) {
return; return;
...@@ -333,7 +335,7 @@ converse.plugins.add('converse-minimize', { ...@@ -333,7 +335,7 @@ converse.plugins.add('converse-minimize', {
} }
} }
} }
}, }, 100),
getOldestMaximizedChat (exclude_ids) { getOldestMaximizedChat (exclude_ids) {
// Get oldest view (if its id is not excluded) // Get oldest view (if its id is not excluded)
...@@ -561,24 +563,10 @@ converse.plugins.add('converse-minimize', { ...@@ -561,24 +563,10 @@ converse.plugins.add('converse-minimize', {
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
const debouncedTrim = _.debounce(ev => { const trimChats = () => _converse.chatboxviews.trimChats();
if (_converse.view_mode !== 'overlayed' || !_converse.chatboxviews.trimChats) { _converse.api.listen.on('controlBoxOpened', trimChats);
return; _converse.api.listen.on('registeredGlobalEventHandlers', () => window.addEventListener("resize", trimChats));
} _converse.api.listen.on('unregisteredGlobalEventHandlers', () => window.removeEventListener("resize", trimChats));
if (_converse.connection.connected) {
_converse.chatboxviews.trimChats();
}
}, 200);
_converse.api.listen.on('registeredGlobalEventHandlers', () => window.addEventListener("resize", debouncedTrim));
_converse.api.listen.on('unregisteredGlobalEventHandlers', () => window.removeEventListener("resize", debouncedTrim));
_converse.api.listen.on('controlBoxOpened', function (chatbox) {
// Wrapped in anon method because at scan time, chatboxviews
// attr not set yet.
if (_converse.connection.connected) {
_converse.chatboxviews.trimChats(chatbox);
}
});
/************************ END Event Handlers ************************/ /************************ END Event Handlers ************************/
} }
}); });
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