瀏覽代碼

Remove unsaved contact if the associated chat is closed

JC Brand 5 月之前
父節點
當前提交
35f6f0eeca

+ 14 - 0
src/headless/plugins/roster/contacts.js

@@ -22,6 +22,20 @@ class RosterContacts extends Collection {
         this.state = new Model({ id, 'collapsed_groups': [] });
         initStorage(this.state, id);
         this.state.fetch();
+
+        api.listen.on('chatBoxClosed',
+            /** @param {import('../../shared/chatbox').default} model */
+            (model) => this.onChatBoxClosed(model));
+    }
+
+    /**
+     * @param {import('../../shared/chatbox').default} model
+     */
+    onChatBoxClosed(model) {
+        const contact = this.get(model.get('jid'));
+        if (contact?.get('subscription') === 'none') {
+            contact.destroy();
+        }
     }
 
     onConnected () {

+ 6 - 4
src/headless/plugins/vcard/plugin.js

@@ -33,9 +33,10 @@ converse.plugins.add('converse-vcard', {
         XMPPStatus: {
             getNickname () {
                 const { _converse } = this.__super__;
+                const { xmppstatus } = _converse.state;
                 const nick = this.__super__.getNickname.apply(this);
-                if (!nick && _converse.state.xmppstatus.vcard) {
-                    return _converse.state.xmppstatus.vcard.get('nickname');
+                if (!nick && xmppstatus?.vcard) {
+                    return xmppstatus.vcard.get('nickname');
                 } else {
                     return nick;
                 }
@@ -43,9 +44,10 @@ converse.plugins.add('converse-vcard', {
 
             getFullname () {
                 const { _converse } = this.__super__;
+                const { xmppstatus } = _converse.state;
                 const fullname = this.__super__.getFullname.apply(this);
-                if (!fullname && _converse.xmppstatus.vcard) {
-                    return _converse.xmppstatus.vcard.get('fullname');
+                if (!fullname && xmppstatus?.vcard) {
+                    return xmppstatus.vcard.get('fullname');
                 } else {
                     return fullname;
                 }

+ 1 - 1
src/headless/types/plugins/chatboxes/chatboxes.d.ts

@@ -22,5 +22,5 @@ declare class ChatBoxes extends Collection {
      */
     createModel(attrs: object, options: object): any;
 }
-import { Collection } from "@converse/skeletor";
+import { Collection } from '@converse/skeletor';
 //# sourceMappingURL=chatboxes.d.ts.map

+ 2 - 2
src/headless/types/plugins/disco/api.d.ts

@@ -119,13 +119,13 @@ declare namespace _default {
                 name: string;
             }, options?: {
                 ignore_cache?: boolean;
-            }): false | import("@converse/skeletor").Model | (Promise<any> & {
+            }): false | import("@converse/skeletor").Model | import("@converse/skeletor/src/types/collection.js").Attributes | (Promise<any> & {
                 isResolved: boolean;
                 isPending: boolean;
                 isRejected: boolean;
                 resolve: Function;
                 reject: Function;
-            }) | import("@converse/skeletor/src/types/collection.js").Attributes;
+            });
         }
         export namespace features_1 {
             /**

+ 4 - 0
src/headless/types/plugins/roster/contacts.d.ts

@@ -4,6 +4,10 @@ declare class RosterContacts extends Collection {
     model: typeof RosterContact;
     data: any;
     state: Model;
+    /**
+     * @param {import('../../shared/chatbox').default} model
+     */
+    onChatBoxClosed(model: import("../../shared/chatbox").default): void;
     onConnected(): void;
     /**
      * Register a handler for roster IQ "set" stanzas, which update

+ 2 - 1
src/plugins/chatview/heading.js

@@ -70,7 +70,8 @@ export default class ChatHeading extends CustomElement {
             },
         ];
 
-        if (await api.disco.supports(Strophe.NS.BLOCKING, _converse.session.get('domain'))) {
+        const domain = _converse.session.get('domain');
+        if (domain && await api.disco.supports(Strophe.NS.BLOCKING, domain)) {
             const blocklist = await api.blocklist.get();
             if (blocklist.get(this.model.get('jid'))) {
                 buttons.push({

+ 1 - 1
src/plugins/omemo/devicelist.js

@@ -9,7 +9,7 @@ const { Strophe, $build, $iq, sizzle } = converse.env;
  * @memberOf _converse
  */
 class DeviceList extends Model {
-    get idAttribute () { // eslint-disable-line class-methods-use-this
+    get idAttribute () {
         return 'jid';
     }