Răsfoiți Sursa

Use stx instead of $iq

JC Brand 2 luni în urmă
părinte
comite
7ee9bd03f7

+ 15 - 18
src/headless/plugins/roster/contacts.js

@@ -7,7 +7,7 @@ import log from '@converse/log';
 import { initStorage } from '../../utils/storage.js';
 import { rejectPresenceSubscription } from './utils.js';
 
-const { Strophe, $iq, sizzle, stx, u, Stanza } = converse.env;
+const { Strophe, sizzle, stx, u, Stanza } = converse.env;
 
 class RosterContacts extends Collection {
     constructor() {
@@ -96,10 +96,10 @@ class RosterContacts extends Collection {
     async fetchRosterContacts() {
         const result = await new Promise((resolve, reject) => {
             this.fetch({
-                'add': true,
-                'silent': true,
-                'success': resolve,
-                'error': (_, e) => reject(e),
+                add: true,
+                silent: true,
+                success: resolve,
+                error: (_, e) => reject(e),
             });
         });
         if (u.isErrorObject(result)) {
@@ -258,7 +258,7 @@ class RosterContacts extends Collection {
             log.warn(`Ignoring roster illegitimate roster push message from ${iq.getAttribute('from')}`);
             return;
         }
-        api.send($iq({ type: 'result', id, from: api.connection.get().jid }));
+        api.send(stx`<iq type="result" id="${id}" from="${api.connection.get().jid}" xmlns="jabber:client" />`);
 
         const query = sizzle(`query[xmlns="${Strophe.NS.ROSTER}"]`, iq).pop();
         this.data.save('version', query.getAttribute('ver'));
@@ -290,20 +290,17 @@ class RosterContacts extends Collection {
     }
 
     /**
-     * Fetch the roster from the XMPP server
+     * Fetches the roster from the XMPP server and updates the local state
      * @emits _converse#roster
-     * @param {boolean} [full=false] - Whether to fetch the full roster or just the changes.
-     * @returns {promise}
+     * @returns {Promise}
      */
-    async fetchFromServer(full = false) {
-        const stanza = $iq({
-            'type': 'get',
-            'id': u.getUniqueId('roster'),
-        }).c('query', { xmlns: Strophe.NS.ROSTER });
-
-        if (this.rosterVersioningSupported() && !full) {
-            stanza.attrs({ 'ver': this.data.get('version') });
-        }
+    async fetchFromServer() {
+        const stanza = stx`
+            <iq type="get" id="${u.getUniqueId('roster')}" xmlns="jabber:client">
+                <query xmlns="${Strophe.NS.ROSTER}"
+                    ${this.rosterVersioningSupported() ? Stanza.unsafeXML(`ver="${this.data.get('version')}"`) : ''}>
+                </query>
+            </iq>`;
 
         const iq = await api.sendIQ(stanza, null, false);
 

+ 5 - 6
src/headless/types/plugins/roster/contacts.d.ts

@@ -66,12 +66,11 @@ declare class RosterContacts extends Collection {
     onRosterPush(iq: Element): void;
     rosterVersioningSupported(): any;
     /**
-     * Fetch the roster from the XMPP server
+     * Fetches the roster from the XMPP server and updates the local state
      * @emits _converse#roster
-     * @param {boolean} [full=false] - Whether to fetch the full roster or just the changes.
-     * @returns {promise}
+     * @returns {Promise}
      */
-    fetchFromServer(full?: boolean): Promise<any>;
+    fetchFromServer(): Promise<any>;
     /**
      * Update or create RosterContact models based on the given `item` XML
      * node received in the resulting IQ stanza from the server.
@@ -95,7 +94,7 @@ declare class RosterContacts extends Collection {
      */
     presenceHandler(presence: Element): true | void;
 }
-import { Collection } from "@converse/skeletor";
+import { Collection } from '@converse/skeletor';
 import RosterContact from './contact.js';
-import { Model } from "@converse/skeletor";
+import { Model } from '@converse/skeletor';
 //# sourceMappingURL=contacts.d.ts.map