Bladeren bron

bugfix: don't set contact on closed chat.

JC Brand 1 maand geleden
bovenliggende
commit
2f52dc71c3

+ 8 - 0
src/headless/shared/model-with-contact.js

@@ -17,6 +17,7 @@ export default function ModelWithContact(BaseModel) {
         initialize() {
             super.initialize();
             this.rosterContactAdded = getOpenPromise();
+            this.onClosedChanged = () => this.setModelContact(this.get('jid'));
             /**
              * @public
              * @type {RosterContact|Profile}
@@ -24,12 +25,19 @@ export default function ModelWithContact(BaseModel) {
             this.contact = null;
         }
 
+
         /**
          * @param {string} jid
          */
         async setModelContact(jid) {
             if (this.contact?.get('jid') === jid) return;
 
+            if (this.get('closed')) {
+                this.off('change:closed', this.onClosedChanged);
+                this.on('change:closed', this.onClosedChanged);
+                return;
+            }
+
             const { session, state } = _converse;
 
             let contact;

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

@@ -208,6 +208,7 @@ declare const ChatBox_base: {
             resolve: (value: any) => void;
             reject: (reason?: any) => void;
         };
+        onClosedChanged: () => Promise<void>;
         contact: import("../roster/contact.js").default | import("../status/profile.js").default;
         setModelContact(jid: string): Promise<void>;
         cid: any;

+ 1 - 0
src/headless/types/shared/message.d.ts

@@ -78,6 +78,7 @@ declare const BaseMessage_base: {
             resolve: (value: any) => void;
             reject: (reason?: any) => void;
         };
+        onClosedChanged: () => Promise<void>;
         contact: import("../index.js").RosterContact | import("../index.js").Profile;
         setModelContact(jid: string): Promise<void>;
         cid: any;

+ 1 - 0
src/headless/types/shared/model-with-contact.d.ts

@@ -16,6 +16,7 @@ export default function ModelWithContact<T extends import("./types").ModelExtend
             resolve: (value: any) => void;
             reject: (reason?: any) => void;
         };
+        onClosedChanged: () => Promise<void>;
         /**
          * @public
          * @type {RosterContact|Profile}