Browse Source

When closing a chat, switch to another chat.

JC Brand 2 weeks ago
parent
commit
80c2ba7a15
2 changed files with 12 additions and 3 deletions
  1. 10 1
      src/headless/plugins/chatboxes/index.js
  2. 2 2
      src/headless/shared/chatbox.js

+ 10 - 1
src/headless/plugins/chatboxes/index.js

@@ -2,12 +2,13 @@
  * @copyright 2022, the Converse.js contributors
  * @license Mozilla Public License (MPLv2)
  */
-import "../emoji/index.js";
 import ChatBoxes from './chatboxes.js';
 import _converse from '../../shared/_converse.js';
 import api from '../../shared/api/index.js';
 import converse from "../../shared/api/public.js";
+import { isUniView } from '../../utils/session.js';
 import chatboxes_api from './api.js';
+import "../emoji/index.js";
 
 const { Strophe } = converse.env;
 
@@ -53,5 +54,13 @@ converse.plugins.add('converse-chatboxes', {
 
         api.listen.on('presencesInitialized', (reconnecting) => chatboxes.onConnected(reconnecting));
         api.listen.on('reconnected', () => chatboxes.forEach(m => m.onReconnection()));
+
+        // XXX: Would be nice to keep track of the last open chat and to show that again.
+        api.listen.on('chatBoxClosed', () => {
+            if (isUniView()) {
+                _converse.state.chatboxes.find((c) => c.get('jid'))?.maybeShow();
+            }
+        });
+
     }
 });

+ 2 - 2
src/headless/shared/chatbox.js

@@ -54,8 +54,8 @@ export default class ChatBoxBase extends ModelWithMessages(Model) {
             if (force || other_chats.length === 0) {
                 // We only have one chat visible at any one time.
                 // So before opening a chat, we make sure all other chats are hidden.
-                other_chats.forEach((c) => u.safeSave(c, { 'hidden': true }));
-                u.safeSave(this, { 'hidden': false });
+                other_chats.forEach((c) => u.safeSave(c, { hidden: true }));
+                u.safeSave(this, { hidden: false });
                 this.trigger('show');
             }
             return this;