Skip to content

Commit

Permalink
Set subscription to to when adding new contact we're subscribing to
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Jan 9, 2025
1 parent a9290d5 commit 95c60e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
21 changes: 11 additions & 10 deletions src/headless/plugins/roster/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
);
}
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -187,7 +188,7 @@ class RosterContacts extends Collection {
nickname: name,
groups: [],
requesting: false,
subscription: 'none',
subscription: subscribe ? 'to' : 'none',
},
...attributes,
},
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions src/headless/types/plugins/disco/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/headless/types/plugins/roster/contacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95c60e4

Please sign in to comment.