From 95c60e4e75944f0f1674c6f24c77c509f75c720a Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 9 Jan 2025 18:22:54 +0200 Subject: [PATCH] Set `subscription` to `to` when adding new contact we're subscribing to --- src/headless/plugins/roster/contacts.js | 21 ++++++++++--------- src/headless/types/plugins/disco/api.d.ts | 4 ++-- .../types/plugins/roster/contacts.d.ts | 8 +++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/headless/plugins/roster/contacts.js b/src/headless/plugins/roster/contacts.js index 6a6dd6effc..ae486482b1 100644 --- a/src/headless/plugins/roster/contacts.js +++ b/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). diff --git a/src/headless/types/plugins/disco/api.d.ts b/src/headless/types/plugins/disco/api.d.ts index 8552629d4b..91ec0a0101 100644 --- a/src/headless/types/plugins/disco/api.d.ts +++ b/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 & { + }): false | import("@converse/skeletor").Model | (Promise & { isResolved: boolean; isPending: boolean; isRejected: boolean; resolve: Function; reject: Function; - }); + }) | import("@converse/skeletor/src/types/collection.js").Attributes; } export namespace features_1 { /** diff --git a/src/headless/types/plugins/roster/contacts.d.ts b/src/headless/types/plugins/roster/contacts.d.ts index 484a0561a5..ea830aad3c 100644 --- a/src/headless/types/plugins/roster/contacts.d.ts +++ b/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} */ - addContact(attributes: import("./types.ts").RosterContactAttributes, persist?: boolean, subscribe?: boolean, message?: string): Promise; + addContact(attributes: import("./types").RosterContactAttributes, persist?: boolean, subscribe?: boolean, message?: string): Promise; /** * @param {string} bare_jid * @param {Element} presence