Răsfoiți Sursa

Fix failing test

JC Brand 3 ani în urmă
părinte
comite
ef2c206507

+ 2 - 5
src/headless/plugins/chat/parsers.js

@@ -23,7 +23,7 @@ import {
     isHeadline,
     isServerMessage,
     isValidReceiptRequest,
-    rejectUnencapsulatedForward,
+    throwErrorIfInvalidForward,
 } from '@converse/headless/shared/parsers';
 
 const { Strophe, sizzle } = converse.env;
@@ -37,10 +37,7 @@ const { Strophe, sizzle } = converse.env;
  * @returns { (MessageAttributes|Error) }
  */
 export async function parseMessage (stanza, _converse) {
-    const err = rejectUnencapsulatedForward(stanza);
-    if (err) {
-        return err;
-    }
+    throwErrorIfInvalidForward(stanza);
 
     let to_jid = stanza.getAttribute('to');
     const to_resource = Strophe.getResourceFromJid(to_jid);

+ 8 - 4
src/headless/plugins/muc/muc.js

@@ -554,13 +554,17 @@ const ChatRoomMixin = {
         }
         /**
          * @typedef { Object } MUCMessageData
-         * An object containing the original groupchat message stanza,
-         * as well as the parsed attributes.
-         * @property { XMLElement } stanza
+         * An object containing the parsed { @link MUCMessageAttributes } and
+         * current { @link ChatRoom }.
          * @property { MUCMessageAttributes } attrs
          * @property { ChatRoom } chatbox
          */
-        const attrs = await parseMUCMessage(stanza, this, _converse);
+        let attrs;
+        try {
+            attrs = await parseMUCMessage(stanza, this, _converse);
+        } catch (e) {
+            return log.error(e.message);
+        }
         const data = { stanza, attrs, 'chatbox': this };
         /**
          * Triggered when a groupchat message stanza has been received and parsed.

+ 2 - 5
src/headless/plugins/muc/parsers.js

@@ -18,7 +18,7 @@ import {
     isCarbon,
     isHeadline,
     isValidReceiptRequest,
-    rejectUnencapsulatedForward,
+    throwErrorIfInvalidForward,
 } from '@converse/headless/shared/parsers';
 import { api, converse } from '@converse/headless/core';
 
@@ -103,10 +103,7 @@ function getModerationAttributes (stanza) {
  * @returns { Promise<MUCMessageAttributes|Error> }
  */
 export async function parseMUCMessage (stanza, chatbox, _converse) {
-    const err = rejectUnencapsulatedForward(stanza);
-    if (err) {
-        return err;
-    }
+    throwErrorIfInvalidForward(stanza);
 
     const selector = `[xmlns="${NS.MAM}"] > forwarded[xmlns="${NS.FORWARD}"] > message`;
     const original_stanza = stanza;

+ 7 - 2
src/headless/shared/parsers.js

@@ -307,12 +307,17 @@ export function isValidReceiptRequest (stanza, attrs) {
     );
 }
 
-export function rejectUnencapsulatedForward (stanza) {
+/**
+ * Check whether the passed-in stanza is a forwarded message that is "bare",
+ * i.e. it's not forwarded as part of a larger protocol, like MAM.
+ * @param { XMLElement } stanza
+ */
+export function throwErrorIfInvalidForward (stanza) {
     const bare_forward = sizzle(`message > forwarded[xmlns="${Strophe.NS.FORWARD}"]`, stanza).length;
     if (bare_forward) {
         rejectMessage(stanza, 'Forwarded messages not part of an encapsulating protocol are not supported');
         const from_jid = stanza.getAttribute('from');
-        return new StanzaParseError(`Ignoring unencapsulated forwarded message from ${from_jid}`, stanza);
+        throw new StanzaParseError(`Ignoring unencapsulated forwarded message from ${from_jid}`, stanza);
     }
 }
 

+ 2 - 3
src/plugins/muc-views/tests/muc-messages.js

@@ -143,10 +143,9 @@ describe("A Groupchat Message", function () {
             </message>
         `);
         const view = _converse.chatboxviews.get(muc_jid);
-        spyOn(view.model, 'onMessage').and.callThrough();
-        spyOn(converse.env.log, 'error');
+        spyOn(converse.env.log, 'error').and.callThrough();
         _converse.connection._dataRecv(mock.createRequest(received_stanza));
-        await u.waitUntil(() => view.model.onMessage.calls.count() === 1);
+        await u.waitUntil(() => converse.env.log.error.calls.count() === 1);
         expect(converse.env.log.error).toHaveBeenCalledWith(
             `Ignoring unencapsulated forwarded message from ${muc_jid}/mallory`
         );