Przeglądaj źródła

bugfix: Don't show closed MUC upon page reload

To remember the resize dimensions of chats, we don't destroy chats that
have custom dimensions, but just close them (i.e. set `closed` to true).
JC Brand 1 miesiąc temu
rodzic
commit
0f36438b58

+ 21 - 14
src/headless/plugins/muc/muc.js

@@ -70,13 +70,14 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
     defaults() {
         /** @type {import('./types').DefaultMUCAttributes} */
         return {
-            'bookmarked': false,
-            'chat_state': undefined,
-            'has_activity': false, // XEP-437
-            'hidden': isUniView() && !api.settings.get('singleton'),
-            'hidden_occupants': !!api.settings.get('hide_muc_participants'),
-            'message_type': 'groupchat',
-            'name': '',
+            bookmarked: false,
+            chat_state: undefined,
+            closed: false,
+            has_activity: false, // XEP-437
+            hidden: isUniView() && !api.settings.get('singleton'),
+            hidden_occupants: !!api.settings.get('hide_muc_participants'),
+            message_type: 'groupchat',
+            name: '',
             // For group chats, we distinguish between generally unread
             // messages and those ones that specifically mention the
             // user.
@@ -85,20 +86,25 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
             // ChatBox to indicate unread messages which
             // mention the user and `num_unread_general` to indicate
             // generally unread messages (which *includes* mentions!).
-            'num_unread_general': 0,
-            'num_unread': 0,
-            'roomconfig': {},
-            'time_opened': this.get('time_opened') || new Date().getTime(),
-            'time_sent': new Date(0).toISOString(),
-            'type': CHATROOMS_TYPE,
+            num_unread_general: 0,
+            num_unread: 0,
+            roomconfig: {},
+            time_opened: this.get('time_opened') || new Date().getTime(),
+            time_sent: new Date(0).toISOString(),
+            type: CHATROOMS_TYPE,
         };
     }
 
     async initialize() {
         super.initialize();
+        this.on('change:closed', () => {
+            if (!this.get('closed')) {
+                this.initialize();
+            }
+        });
+        if (this.get('closed')) return;
 
         this.initialized = getOpenPromise();
-
         this.debouncedRejoin = debounce(this.rejoin, 250);
 
         this.initOccupants();
@@ -122,6 +128,7 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
         if (!restored) {
             await this.join();
         }
+
         /**
          * Triggered once a {@link MUC} has been created and initialized.
          * @event _converse#chatRoomInitialized

+ 1 - 0
src/headless/types/plugins/muc/muc.d.ts

@@ -288,6 +288,7 @@ declare class MUC extends MUC_base {
     defaults(): {
         bookmarked: boolean;
         chat_state: any;
+        closed: boolean;
         has_activity: boolean;
         hidden: boolean;
         hidden_occupants: boolean;

+ 5 - 4
src/plugins/omemo/index.js

@@ -24,7 +24,7 @@ import {
     handleMessageSendError,
     initOMEMO,
     omemo,
-    onChatBoxesInitialized,
+    onChatComponentInitialized,
     onChatInitialized,
     parseEncryptedMessage,
     registerPEPPushHandler,
@@ -73,8 +73,9 @@ converse.plugins.add("converse-omemo", {
         Object.assign(_converse.exports, exports);
 
         /******************** Event Handlers ********************/
-        api.waitUntil("chatBoxesInitialized").then(onChatBoxesInitialized);
 
+        api.listen.on('chatRoomInitialized', onChatInitialized);
+        api.listen.on('chatBoxInitialized', onChatInitialized);
         api.listen.on("getOutgoingMessageAttributes", getOutgoingMessageAttributes);
 
         api.listen.on("createMessageStanza", async (chat, data) => {
@@ -94,8 +95,8 @@ converse.plugins.add("converse-omemo", {
         api.listen.on("parseMessage", parseEncryptedMessage);
         api.listen.on("parseMUCMessage", parseEncryptedMessage);
 
-        api.listen.on("chatBoxViewInitialized", onChatInitialized);
-        api.listen.on("chatRoomViewInitialized", onChatInitialized);
+        api.listen.on("chatBoxViewInitialized", onChatComponentInitialized);
+        api.listen.on("chatRoomViewInitialized", onChatComponentInitialized);
 
         api.listen.on("connected", registerPEPPushHandler);
         api.listen.on("getToolbarButtons", getOMEMOToolbarButton);

+ 8 - 11
src/plugins/omemo/utils.js

@@ -18,7 +18,6 @@ import { MIMETYPES_MAP } from 'utils/file.js';
 import { IQError, UserFacingError } from 'shared/errors.js';
 import DeviceLists from './devicelists.js';
 import { getFileName } from 'utils/html.js';
-import { Texture } from 'shared/texture/texture.js';
 
 const { Strophe, sizzle, stx } = converse.env;
 const { CHATROOMS_TYPE, PRIVATE_CHAT_TYPE } = constants;
@@ -275,7 +274,7 @@ async function getAndDecryptFile(url_text) {
 /**
  * @param {string} file_url
  * @param {string|Error} obj_url
- * @param {Texture} richtext
+ * @param {import('shared/texture/texture.js').Texture} richtext
  * @returns {import("lit").TemplateResult}
  */
 function getTemplateForObjectURL(file_url, obj_url, richtext) {
@@ -395,17 +394,15 @@ export async function parseEncryptedMessage(stanza, attrs) {
     }
 }
 
-export function onChatBoxesInitialized() {
-    _converse.state.chatboxes.on('add', (chatbox) => {
-        checkOMEMOSupported(chatbox);
-        if (chatbox.get('type') === CHATROOMS_TYPE) {
-            chatbox.occupants.on('add', (o) => onOccupantAdded(chatbox, o));
-            chatbox.features.on('change', () => checkOMEMOSupported(chatbox));
-        }
-    });
+export function onChatInitialized(chatbox) {
+    checkOMEMOSupported(chatbox);
+    if (chatbox.get('type') === CHATROOMS_TYPE) {
+        chatbox.occupants.on('add', (o) => onOccupantAdded(chatbox, o));
+        chatbox.features.on('change', () => checkOMEMOSupported(chatbox));
+    }
 }
 
-export function onChatInitialized(el) {
+export function onChatComponentInitialized(el) {
     el.listenTo(el.model.messages, 'add', (message) => {
         if (message.get('is_encrypted') && !message.get('is_error')) {
             el.model.save('omemo_supported', true);

+ 1 - 1
src/types/plugins/bookmark-views/modals/bookmark-list.d.ts

@@ -2,5 +2,5 @@ export default class BookmarkListModal extends BaseModal {
     renderModal(): import("lit-html").TemplateResult<1>;
     getModalTitle(): any;
 }
-import BaseModal from "plugins/modal/modal.js";
+import BaseModal from 'plugins/modal/modal.js';
 //# sourceMappingURL=bookmark-list.d.ts.map

+ 5 - 5
src/types/plugins/omemo/utils.d.ts

@@ -49,8 +49,8 @@ export function handleEncryptedFiles(richtext: import("shared/texture/texture.js
         import('./types').MUCMessageAttrsWithEncryption|import('./types').MessageAttrsWithEncryption>}
  */
 export function parseEncryptedMessage(stanza: Element, attrs: MUCMessageAttributes | MessageAttributes): Promise<MUCMessageAttributes | MessageAttributes | import("./types").MUCMessageAttrsWithEncryption | import("./types").MessageAttrsWithEncryption>;
-export function onChatBoxesInitialized(): void;
-export function onChatInitialized(el: any): void;
+export function onChatInitialized(chatbox: any): void;
+export function onChatComponentInitialized(el: any): void;
 /**
  * @param {string} jid
  * @param {number} id
@@ -123,9 +123,9 @@ export type MessageAttributes = import("@converse/headless/shared/types").Messag
 export type MUCMessageAttributes = import("@converse/headless/plugins/muc/types").MUCMessageAttributes;
 export type ChatBox = import("@converse/headless").ChatBox;
 export type BaseMessage = import("@converse/headless").BaseMessage<any>;
-import { IQError } from "shared/errors.js";
-import { UserFacingError } from "shared/errors.js";
-import { MUC } from "@converse/headless";
+import { IQError } from 'shared/errors.js';
+import { UserFacingError } from 'shared/errors.js';
+import { MUC } from '@converse/headless';
 /**
  * @param {import('./types').EncryptedMessage} obj
  * @returns {Promise<string>}