Просмотр исходного кода

Updates #3605

Make sure the RSM xmlns is set in Firefox
JC Brand 4 месяцев назад
Родитель
Сommit
dcfdb0557e

+ 2 - 2
src/headless/plugins/mam/api.js

@@ -4,7 +4,7 @@ import converse from '../../shared/api/public.js';
 import dayjs from 'dayjs';
 import log from '../../log.js';
 import sizzle from "sizzle";
-import { RSM } from '../../shared/rsm';
+import { RSM } from '../../shared/rsm.js';
 import { Strophe, Stanza } from 'strophe.js';
 import { TimeoutError } from '../../shared/errors.js';
 
@@ -254,7 +254,7 @@ export default {
                             </x>`
                                 : ""
                         }
-                        ${Object.keys(rsm.query ?? {}).length ? stx`${Stanza.unsafeXML(rsm.toXML().outerHTML)}` : ""}
+                        ${Object.keys(rsm.query ?? {}).length ? Stanza.fromString(rsm.toString()) : ""}
                     </query>
                 </iq>`;
 

+ 24 - 7
src/headless/shared/rsm.js

@@ -1,13 +1,12 @@
 /**
- * @module converse-rsm
  * @copyright The Converse.js contributors
  * @license Mozilla Public License (MPLv2)
  * @description XEP-0059 Result Set Management
  *   Some code taken from the Strophe RSM plugin, licensed under the MIT License
  *   Copyright 2006-2017 Strophe (https://github.com/strophe/strophejs)
  */
+import { isUndefined } from "../utils/object.js";
 import converse from "./api/public.js";
-import pick from "lodash-es/pick";
 
 const { Strophe, $build } = converse.env;
 
@@ -28,8 +27,6 @@ export const RSM_TYPES = {
     max: toNumber,
 };
 
-const isUndefined = (x) => typeof x === "undefined";
-
 // This array contains both query attributes and response attributes
 export const RSM_ATTRIBUTES = Object.keys(RSM_TYPES);
 
@@ -39,7 +36,12 @@ export const RSM_ATTRIBUTES = Object.keys(RSM_TYPES);
  */
 export class RSM {
     static getQueryParameters(options = {}) {
-        return pick(options, RSM_QUERY_PARAMETERS);
+        return RSM_QUERY_PARAMETERS.reduce((result, key) => {
+            if (options[key] !== undefined) {
+                result[key] = options[key];
+            }
+            return result;
+        }, {});
     }
 
     static parseXMLResult(set) {
@@ -58,9 +60,8 @@ export class RSM {
     }
 
     /**
-     * Create a new RSM instance
+     * Creates a new RSM instance
      * @param { Object } options - Configuration options
-     * @constructor
      */
     constructor(options = {}) {
         this.query = RSM.getQueryParameters(options);
@@ -85,11 +86,27 @@ export class RSM {
         return RSM_QUERY_PARAMETERS.reduce(reducer, xml).tree();
     }
 
+    /**
+     * Returns a string representation of the result-set XML
+     * @returns {string}
+     */
+    toString() {
+        return Strophe.serialize(this.toXML());
+    }
+
+    /**
+     * @param {string} max
+     * @param {string} before
+     */
     next(max, before) {
         const options = Object.assign({}, this.query, { after: this.result.last, before, max });
         return new RSM(options);
     }
 
+    /**
+     * @param {string} max
+     * @param {string} after
+     */
     previous(max, after) {
         const options = Object.assign({}, this.query, { after, before: this.result.first, max });
         return new RSM(options);

+ 18 - 6
src/headless/types/shared/rsm.d.ts

@@ -13,17 +13,16 @@ export const RSM_ATTRIBUTES: string[];
  * @class RSM
  */
 export class RSM {
-    static getQueryParameters(options?: {}): Partial<{}>;
+    static getQueryParameters(options?: {}): {};
     static parseXMLResult(set: any): {
         index: number;
     };
     /**
-     * Create a new RSM instance
+     * Creates a new RSM instance
      * @param { Object } options - Configuration options
-     * @constructor
      */
     constructor(options?: any);
-    query: Partial<{}>;
+    query: {};
     result: {};
     /**
      * Returns a `<set>` XML element that confirms to XEP-0059 Result Set Management.
@@ -32,8 +31,21 @@ export class RSM {
      * @returns {Element}
      */
     toXML(): Element;
-    next(max: any, before: any): RSM;
-    previous(max: any, after: any): RSM;
+    /**
+     * Returns a string representation of the result-set XML
+     * @returns {string}
+     */
+    toString(): string;
+    /**
+     * @param {string} max
+     * @param {string} before
+     */
+    next(max: string, before: string): RSM;
+    /**
+     * @param {string} max
+     * @param {string} after
+     */
+    previous(max: string, after: string): RSM;
 }
 declare function toString(v: any): any;
 declare function toNumber(v: any): number;

+ 3 - 2
src/headless/types/utils/index.d.ts

@@ -61,8 +61,9 @@ declare const _default: {
     waitUntil(func: Function, max_wait?: number, check_delay?: number): Promise<any>;
     getOpenPromise: any;
     merge(dst: any, src: any): void;
-    isError(obj: any): boolean;
-    isFunction(val: any): boolean;
+    isError(obj: unknown): boolean;
+    isFunction(val: unknown): boolean;
+    isUndefined(x: unknown): boolean;
     isValidJID(jid?: string | null): boolean;
     isValidMUCJID(jid: string): boolean;
     isSameBareJID(jid1: string, jid2: string): boolean;

+ 15 - 2
src/headless/types/utils/object.d.ts

@@ -4,6 +4,19 @@
  * @param {Object} src
  */
 export function merge(dst: any, src: any): void;
-export function isError(obj: any): boolean;
-export function isFunction(val: any): boolean;
+/**
+ * @param {unknown} obj - The object to check.
+ * @returns {boolean} True if the object is an Error, false otherwise.
+ */
+export function isError(obj: unknown): boolean;
+/**
+ * @param {unknown} val - The value to check.
+ * @returns {boolean} True if the value is a function, false otherwise.
+ */
+export function isFunction(val: unknown): boolean;
+/**
+ * @param {unknown} x - The value to check.
+ * @returns {boolean} True if the value is undefined, false otherwise.
+ */
+export function isUndefined(x: unknown): boolean;
 //# sourceMappingURL=object.d.ts.map

+ 22 - 6
src/headless/utils/object.js

@@ -3,10 +3,10 @@
  * @param {Object} dst
  * @param {Object} src
  */
-export function merge (dst, src) {
+export function merge(dst, src) {
     for (const k in src) {
         if (!Object.prototype.hasOwnProperty.call(src, k)) continue;
-        if (k === '__proto__' || k === 'constructor') continue;
+        if (k === "__proto__" || k === "constructor") continue;
 
         if (dst[k] instanceof Object) {
             merge(dst[k], src[k]);
@@ -16,10 +16,26 @@ export function merge (dst, src) {
     }
 }
 
-export function isError (obj) {
-    return Object.prototype.toString.call(obj) === '[object Error]';
+/**
+ * @param {unknown} obj - The object to check.
+ * @returns {boolean} True if the object is an Error, false otherwise.
+ */
+export function isError(obj) {
+    return Object.prototype.toString.call(obj) === "[object Error]";
+}
+
+/**
+ * @param {unknown} val - The value to check.
+ * @returns {boolean} True if the value is a function, false otherwise.
+ */
+export function isFunction(val) {
+    return typeof val === "function";
 }
 
-export function isFunction (val) {
-    return typeof val === 'function';
+/**
+ * @param {unknown} x - The value to check.
+ * @returns {boolean} True if the value is undefined, false otherwise.
+ */
+export function isUndefined(x) {
+    return typeof x === "undefined";
 }