Pārlūkot izejas kodu

Update to latest Strophe

and use `stx` and `toStanza` from there.
JC Brand 1 gadu atpakaļ
vecāks
revīzija
3f0a81973f

+ 3 - 3
package-lock.json

@@ -9968,8 +9968,8 @@
     },
     "node_modules/strophe.js": {
       "version": "2.0.0",
-      "resolved": "git+ssh://git@github.com/strophe/strophejs.git#a1a9e418a49dee56e6c42a1b67be118e7cd3f5bc",
-      "integrity": "sha512-aZ4pzuca9Bb1jBTZHlk8qa/K9+Ey0whey8TIe9b+0DeRWhxd0YQBL2KlXz6g3sLFuy3TuITsfubMMsSpVBe1dg==",
+      "resolved": "git+ssh://git@github.com/strophe/strophejs.git#6b24a2a2121884b2d02aeb5756142f7dcaf05d9e",
+      "integrity": "sha512-YIK1PUyJEwZgiPk30cEtxhN5ifLzyLOnch9T6tw7812pO2yuaGdBEQcqGd8NQjH3LzdcoS/DZJnXFxj+QKyviQ==",
       "license": "MIT",
       "dependencies": {
         "abab": "^2.0.3"
@@ -11276,7 +11276,7 @@
         "pluggable.js": "3.0.1",
         "sizzle": "^2.3.5",
         "sprintf-js": "^1.1.2",
-        "strophe.js": "strophe/strophejs#a1a9e418a49dee56e6c42a1b67be118e7cd3f5bc",
+        "strophe.js": "strophe/strophejs#6b24a2a2121884b2d02aeb5756142f7dcaf05d9e",
         "urijs": "^1.19.10"
       },
       "devDependencies": {}

+ 1 - 1
src/headless/package.json

@@ -41,7 +41,7 @@
     "pluggable.js": "3.0.1",
     "sizzle": "^2.3.5",
     "sprintf-js": "^1.1.2",
-    "strophe.js": "strophe/strophejs#a1a9e418a49dee56e6c42a1b67be118e7cd3f5bc",
+    "strophe.js": "strophe/strophejs#6b24a2a2121884b2d02aeb5756142f7dcaf05d9e",
     "urijs": "^1.19.10"
   },
   "devDependencies": {}

+ 1 - 2
src/headless/shared/api/public.js

@@ -10,13 +10,12 @@ import { ANONYMOUS, CHAT_STATES, KEYCODES, VERSION_NAME } from '../constants.js'
 import { setUnloadEvent, isTestEnv } from '../../utils/session.js';
 import { Collection } from "@converse/skeletor/src/collection";
 import { Model } from '@converse/skeletor/src/model.js';
-import { Strophe, $build, $iq, $msg, $pres } from 'strophe.js';
+import { Strophe, $build, $iq, $msg, $pres, stx } from 'strophe.js';
 import { TimeoutError } from '../errors.js';
 import { filesize } from 'filesize';
 import { html } from 'lit';
 import { initAppSettings } from '../settings/utils.js';
 import { sprintf } from 'sprintf-js';
-import { stx } from '../../utils/stanza.js';
 
 import {
     cleanup,

+ 1 - 2
src/headless/shared/api/send.js

@@ -1,8 +1,7 @@
 import _converse from '../_converse.js';
 import log from '../../log.js';
-import { Strophe } from 'strophe.js';
+import { Strophe, toStanza } from 'strophe.js';
 import { TimeoutError } from '../errors.js';
-import { toStanza } from '../../utils/stanza.js';
 
 export default {
     /**

+ 1 - 1
src/headless/utils/form.js

@@ -3,7 +3,7 @@
  * @license Mozilla Public License (MPLv2)
  * @description This is the form utilities module.
  */
-import { toStanza } from './stanza.js';
+import { toStanza } from 'strophe.js';
 
 /**
  * @param {string} name

+ 1 - 3
src/headless/utils/index.js

@@ -6,9 +6,8 @@
 import DOMPurify from 'dompurify';
 import sizzle from "sizzle";
 import { Model } from '@converse/skeletor/src/model.js';
-import { Strophe } from 'strophe.js';
+import { Strophe, toStanza } from 'strophe.js';
 import { getOpenPromise } from '@converse/openpromise';
-import { stx , toStanza } from './stanza.js';
 import { saveWindowState, shouldClearCache } from './session.js';
 import { merge, isError, isFunction } from './object.js';
 import { createStore, getDefaultStore } from './storage.js';
@@ -288,7 +287,6 @@ export default Object.assign({
     saveWindowState,
     shouldClearCache,
     stringToElement,
-    stx,
     toStanza,
     triggerEvent,
     waitUntil, // TODO: remove. Only the API should be used

+ 0 - 63
src/headless/utils/stanza.js

@@ -1,63 +0,0 @@
-import log from '../log.js';
-import { Strophe } from 'strophe.js';
-
-const PARSE_ERROR_NS = 'http://www.w3.org/1999/xhtml';
-
-export function toStanza (string, throwErrorIfInvalidNS) {
-    const doc = Strophe.xmlHtmlNode(string);
-
-    if (doc.getElementsByTagNameNS(PARSE_ERROR_NS, 'parsererror').length) {
-        throw new Error(`Parser Error: ${string}`);
-    }
-
-    const node = doc.firstElementChild;
-
-    if (
-        ['message', 'iq', 'presence'].includes(node.nodeName.toLowerCase()) &&
-        node.namespaceURI !== 'jabber:client' &&
-        node.namespaceURI !== 'jabber:server'
-    ) {
-        const err_msg = `Invalid namespaceURI ${node.namespaceURI}`;
-        log.error(err_msg);
-        if (throwErrorIfInvalidNS) throw new Error(err_msg);
-    }
-    return node;
-}
-
-/**
- * A Stanza represents a XML element used in XMPP (commonly referred to as
- * stanzas).
- */
-class Stanza {
-
-    constructor (strings, values) {
-        this.strings = strings;
-        this.values = values;
-    }
-
-    toString () {
-        this.string = this.string ||
-             this.strings.reduce((acc, str) => {
-                const idx = this.strings.indexOf(str);
-                const value = this.values.length > idx ? this.values[idx].toString() : '';
-                return acc + str + value;
-            }, '');
-        return this.string;
-    }
-
-    tree () {
-        this.node = this.node ?? toStanza(this.toString(), true);
-        return this.node;
-    }
-}
-
-/**
- * Tagged template literal function which generates {@link Stanza } objects
- *
- * Similar to the `html` function, from Lit.
- *
- * @example stx`<presence type="${type}"><show>${show}</show></presence>`
- */
-export function stx (strings, ...values) {
-    return new Stanza(strings, values);
-}