浏览代码

Rename the `stanza` TTL to `stx` to avoid name clashes

JC Brand 2 年之前
父节点
当前提交
f1cc8c85f4

+ 1 - 1
src/headless/core.js

@@ -762,7 +762,7 @@ Object.assign(converse, {
         log,
         sizzle,
         sprintf,
-        stanza: u.stanza,
+        stx: u.stx,
         u,
     }
 });

+ 2 - 2
src/headless/utils/core.js

@@ -16,7 +16,7 @@ import { Strophe } from 'strophe.js/src/strophe.js';
 import { getOpenPromise } from '@converse/openpromise';
 import { setUserJID, } from '@converse/headless/utils/init.js';
 import { settings_api } from '@converse/headless/shared/settings/api.js';
-import { stanza, toStanza } from './stanza.js';
+import { stx , toStanza } from './stanza.js';
 
 export function isEmptyMessage (attrs) {
     if (attrs instanceof Model) {
@@ -577,5 +577,5 @@ export default Object.assign({
     isEmptyMessage,
     getUniqueId,
     toStanza,
-    stanza,
+    stx,
 }, u);

+ 7 - 1
src/headless/utils/stanza.js

@@ -11,7 +11,13 @@ export function toStanza (string) {
 }
 
 
-export function stanza (strings, ...values) {
+/**
+ * Tagged template literal function which can be used to generate XML stanzas.
+ * Similar to the `html` function, from Lit.
+ *
+ * @example stx`<presence type="${type}"><show>${show}</show></presence>`
+ */
+export function stx (strings, ...values) {
     return toStanza(
         strings.reduce((acc, str) => {
             const idx = strings.indexOf(str);

+ 4 - 4
src/plugins/muc-views/tests/corrections.js

@@ -1,6 +1,6 @@
 /*global mock, converse */
 
-const { $msg, $pres, Strophe, u, stanza } = converse.env;
+const { $msg, $pres, Strophe, u, stx } = converse.env;
 
 describe("A Groupchat Message", function () {
 
@@ -274,7 +274,7 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
 
             const msg_id = u.getUniqueId();
             await model.handleMessageStanza(
-                stanza`
+                stx`
                 <message
                     from="lounge@montague.lit/newguy"
                     to="_converse.connection.jid"
@@ -291,7 +291,7 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
             expect(model.messages.at(0).get('body')).toBe('But soft, what light through yonder airlock breaks?');
 
             await model.handleMessageStanza(
-                stanza`
+                stx`
                 <message
                     from="lounge@montague.lit/newguy"
                     to="_converse.connection.jid"
@@ -312,7 +312,7 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
             expect(model.messages.at(1).get('edited')).toBeFalsy();
 
             await model.handleMessageStanza(
-                stanza`
+                stx`
                 <message
                     from="lounge@montague.lit/newguy"
                     to="_converse.connection.jid"

+ 3 - 4
src/plugins/muc-views/tests/nickname.js

@@ -1,13 +1,12 @@
 /*global mock, converse */
 
-const { $pres, $iq, Strophe, sizzle, u } = converse.env;
+const { $pres, $iq, Strophe, sizzle, u, stx } = converse.env;
 
 describe("A MUC", function () {
 
     it("allows you to change your nickname via a modal",
             mock.initConverse([], {'view_mode': 'fullscreen'}, async function (_converse) {
 
-        const { stanza } = converse.env;
         const muc_jid = 'lounge@montague.lit';
         const nick = 'romeo';
         const model = await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
@@ -39,7 +38,7 @@ describe("A MUC", function () {
 
         // Two presence stanzas are received from the MUC service
         _converse.connection._dataRecv(mock.createRequest(
-            stanza`
+            stx`
             <presence
                 from='${muc_jid}/${nick}'
                 id='DC352437-C019-40EC-B590-AF29E879AF98'
@@ -59,7 +58,7 @@ describe("A MUC", function () {
         expect(model.get('nick')).toBe(newnick);
 
         _converse.connection._dataRecv(mock.createRequest(
-            stanza`
+            stx`
             <presence
                 from='${muc_jid}/${newnick}'
                 id='5B4F27A4-25ED-43F7-A699-382C6B4AFC67'