Răsfoiți Sursa

Set `subscription` to `to` when adding new contact we're subscribing to

JC Brand 6 luni în urmă
părinte
comite
1254a184f7

+ 11 - 10
src/headless/plugins/roster/contacts.js

@@ -124,10 +124,11 @@ class RosterContacts extends Collection {
         const { xmppstatus } = _converse.state;
         Array.from(msg.querySelectorAll('item')).forEach((item) => {
             if (item.getAttribute('action') === 'add') {
-                _converse.state.roster.addContact(
+                this.addContact(
                     {
                         jid: item.getAttribute('jid'),
                         name: xmppstatus.getNickname() || xmppstatus.getFullname(),
+                        subscription: 'to',
                     },
                 );
             }
@@ -144,7 +145,7 @@ class RosterContacts extends Collection {
 
     /**
      * Send an IQ stanza to the XMPP server to add a new roster contact.
-     * @param {import('./types.ts').RosterContactAttributes} attributes
+     * @param {import('./types').RosterContactAttributes} attributes
      */
     sendContactAddIQ (attributes) {
         const { jid, groups } = attributes;
@@ -158,7 +159,7 @@ class RosterContacts extends Collection {
      * Adds a {@link RosterContact} instance to {@link RosterContacts} and
      * optionally (if subscribe=true) subscribe to the contact's presence
      * updates which also adds the contact to the roster on the XMPP server.
-     * @param {import('./types.ts').RosterContactAttributes} attributes
+     * @param {import('./types').RosterContactAttributes} attributes
      * @param {boolean} [persist=true] - Whether the contact should be persisted to the user's roster.
      * @param {boolean} [subscribe=true] - Whether we should subscribe to the contacts presence updates.
      * @param {string} [message=''] - An optional message to include with the presence subscription
@@ -187,7 +188,7 @@ class RosterContacts extends Collection {
                     nickname: name,
                     groups: [],
                     requesting: false,
-                    subscription: 'none',
+                    subscription: subscribe ? 'to' : 'none',
                 },
                 ...attributes,
             },
@@ -356,14 +357,14 @@ class RosterContacts extends Collection {
      * @param {Element} presence
      */
     createRequestingContact (presence) {
-        const bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
+        const jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
         const nickname = sizzle(`nick[xmlns="${Strophe.NS.NICK}"]`, presence).pop()?.textContent || null;
         const user_data = {
-            'jid': bare_jid,
-            'subscription': 'none',
-            'ask': null,
-            'requesting': true,
-            'nickname': nickname,
+            jid,
+            subscription: 'none',
+            ask: null,
+            requesting: true,
+            nickname: nickname,
         };
         /**
          * Triggered when someone has requested to subscribe to your presence (i.e. to be your contact).

+ 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 | import("@converse/skeletor/src/types/collection.js").Attributes | (Promise<any> & {
+            }): false | import("@converse/skeletor").Model | (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 - 4
src/headless/types/plugins/roster/contacts.d.ts

@@ -35,20 +35,20 @@ declare class RosterContacts extends Collection {
     isSelf(jid: string): any;
     /**
      * Send an IQ stanza to the XMPP server to add a new roster contact.
-     * @param {import('./types.ts').RosterContactAttributes} attributes
+     * @param {import('./types').RosterContactAttributes} attributes
      */
-    sendContactAddIQ(attributes: import("./types.ts").RosterContactAttributes): any;
+    sendContactAddIQ(attributes: import("./types").RosterContactAttributes): any;
     /**
      * Adds a {@link RosterContact} instance to {@link RosterContacts} and
      * optionally (if subscribe=true) subscribe to the contact's presence
      * updates which also adds the contact to the roster on the XMPP server.
-     * @param {import('./types.ts').RosterContactAttributes} attributes
+     * @param {import('./types').RosterContactAttributes} attributes
      * @param {boolean} [persist=true] - Whether the contact should be persisted to the user's roster.
      * @param {boolean} [subscribe=true] - Whether we should subscribe to the contacts presence updates.
      * @param {string} [message=''] - An optional message to include with the presence subscription
      * @returns {Promise<RosterContact>}
      */
-    addContact(attributes: import("./types.ts").RosterContactAttributes, persist?: boolean, subscribe?: boolean, message?: string): Promise<RosterContact>;
+    addContact(attributes: import("./types").RosterContactAttributes, persist?: boolean, subscribe?: boolean, message?: string): Promise<RosterContact>;
     /**
      * @param {string} bare_jid
      * @param {Element} presence