minimize: initialize chat via event instead of override

This commit is contained in:
JC Brand 2022-02-19 22:54:17 +01:00
parent bbef09346a
commit ca20f687bf
2 changed files with 14 additions and 16 deletions

View File

@ -12,6 +12,7 @@ import { _converse, api, converse } from '@converse/headless/core';
import {
addMinimizeButtonToChat,
addMinimizeButtonToMUC,
initializeChat,
maximize,
minimize,
onMinimizedChanged,
@ -20,8 +21,6 @@ import {
import './styles/minimize.scss';
const { dayjs } = converse.env;
converse.plugins.add('converse-minimize', {
/* Optional dependencies are other plugins which might be
@ -56,19 +55,6 @@ converse.plugins.add('converse-minimize', {
// New functions which don't exist yet can also be added.
ChatBox: {
initialize () {
this.__super__.initialize.apply(this, arguments);
this.on('change:hidden', m => !m.get('hidden') && maximize(this), this);
if (this.get('id') === 'controlbox') {
return;
}
this.save({
'minimized': this.get('minimized') || false,
'time_minimized': this.get('time_minimized') || dayjs(),
});
},
maybeShow (force) {
if (!force && this.get('minimized')) {
// Must return the chatbox
@ -112,6 +98,7 @@ converse.plugins.add('converse-minimize', {
_converse.minimize = { trimChats, minimize, maximize };
function onChatInitialized (model) {
initializeChat(model);
model.on( 'change:minimized', () => onMinimizedChanged(model));
}

View File

@ -1,8 +1,19 @@
import { _converse, api, converse } from '@converse/headless/core';
import { __ } from 'i18n';
const u = converse.env.utils;
const { dayjs, u } = converse.env;
export function initializeChat (chat) {
chat.on('change:hidden', m => !m.get('hidden') && maximize(chat), chat);
if (chat.get('id') === 'controlbox') {
return;
}
chat.save({
'minimized': chat.get('minimized') || false,
'time_minimized': chat.get('time_minimized') || dayjs(),
});
}
function getChatBoxWidth (view) {
if (view.model.get('id') === 'controlbox') {