Pārlūkot izejas kodu

mod_ogp now sends messages with `type="groupchat"`

JC Brand 4 gadi atpakaļ
vecāks
revīzija
ccfa00d7b8

+ 4 - 3
spec/unfurls.js

@@ -23,7 +23,7 @@ describe("A Groupchat Message", function () {
         expect(el.textContent).toBe('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
 
         const metadata_stanza = u.toStanza(`
-            <message xmlns="jabber:client" from="${muc_jid}" to="${_converse.jid}">
+            <message xmlns="jabber:client" from="${muc_jid}" to="${_converse.jid}" type="groupchat">
                 <apply-to xmlns="urn:xmpp:fasten:0" id="eda6c790-b4f3-4c07-b5e2-13fff99e6c04">
                     <meta xmlns="http://www.w3.org/1999/xhtml" property="og:site_name" content="YouTube" />
                     <meta xmlns="http://www.w3.org/1999/xhtml" property="og:url" content="https://www.youtube.com/watch?v=dQw4w9WgXcQ" />
@@ -66,7 +66,7 @@ describe("A Groupchat Message", function () {
         expect(el.textContent).toBe('Check out https://www.youtube.com/watch?v=dQw4w9WgXcQ and https://duckduckgo.com');
 
         let metadata_stanza = u.toStanza(`
-            <message xmlns="jabber:client" from="${muc_jid}" to="${_converse.jid}">
+            <message xmlns="jabber:client" from="${muc_jid}" to="${_converse.jid}" type="groupchat">
                 <apply-to xmlns="urn:xmpp:fasten:0" id="eda6c790-b4f3-4c07-b5e2-13fff99e6c04">
                     <meta xmlns="http://www.w3.org/1999/xhtml" property="og:site_name" content="YouTube" />
                     <meta xmlns="http://www.w3.org/1999/xhtml" property="og:url" content="https://www.youtube.com/watch?v=dQw4w9WgXcQ" />
@@ -84,9 +84,10 @@ describe("A Groupchat Message", function () {
                 </apply-to>
             </message>`);
         _converse.connection._dataRecv(mock.createRequest(metadata_stanza));
+        await u.waitUntil(() => view.querySelectorAll('converse-message-unfurl').length === 1);
 
         metadata_stanza = u.toStanza(`
-            <message xmlns="jabber:client" from="${muc_jid}" to="${_converse.jid}">
+            <message xmlns="jabber:client" from="${muc_jid}" to="${_converse.jid}" type="groupchat">
                 <apply-to xmlns="urn:xmpp:fasten:0" id="eda6c790-b4f3-4c07-b5e2-13fff99e6c04">
                     <meta xmlns="http://www.w3.org/1999/xhtml" property="og:url" content="https://duckduckgo.com/" />
                     <meta xmlns="http://www.w3.org/1999/xhtml" property="og:site_name" content="DuckDuckGo" />

+ 8 - 13
src/headless/plugins/chat/model.js

@@ -6,7 +6,6 @@ import log from '@converse/headless/log';
 import pick from "lodash/pick";
 import { Model } from '@converse/skeletor/src/model.js';
 import { _converse, api, converse } from "../../core.js";
-import { getOpenGraphMetadata } from '@converse/headless/shared/parsers';
 import { parseMessage } from './parsers.js';
 import { sendMarker } from '@converse/headless/shared/actions';
 
@@ -489,19 +488,15 @@ const ChatBox = ModelWithContact.extend({
         return false;
     },
 
-    handleMetadataFastening (stanza) {
-        const attrs = getOpenGraphMetadata(stanza);
+    handleMetadataFastening (attrs) {
         if (attrs.ogp_for_id) {
-            if (attrs.ogp_for_id) {
-                const message = this.messages.findWhere({'origin_id': attrs.ogp_for_id});
-                if (message) {
-                    const list = message.get('ogp_metadata') || [];
-                    list.push(pick(attrs, METADATA_ATTRIBUTES));
-                    message.save('ogp_metadata', list);
-                    return true;
-                } else {
-                    return false;
-                }
+            const message = this.messages.findWhere({'origin_id': attrs.ogp_for_id});
+            if (message) {
+                const list = [...(message.get('ogp_metadata') || []), pick(attrs, METADATA_ATTRIBUTES)];
+                message.save('ogp_metadata', list);
+                return true;
+            } else {
+                return false;
             }
         }
         return false;

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

@@ -495,17 +495,15 @@ const ChatRoomMixin = {
      */
     async handleMessageStanza (stanza) {
         if (stanza.getAttribute('type') !== 'groupchat') {
-            this.handleMetadataFastening(stanza);
             this.handleForwardedMentions(stanza);
             return;
-        }
-
-        if (isArchived(stanza)) {
+        } else if (isArchived(stanza)) {
             // MAM messages are handled in converse-mam.
             // We shouldn't get MAM messages here because
             // they shouldn't have a `type` attribute.
             return log.warn(`Received a MAM message with type "groupchat"`);
         }
+
         this.createInfoMessages(stanza);
         this.fetchFeaturesIfConfigurationChanged(stanza);
 
@@ -2128,11 +2126,13 @@ const ChatRoomMixin = {
         }
 
         if (
+            this.handleMetadataFastening(attrs) ||
             (await this.handleRetraction(attrs)) ||
             (await this.handleModeration(attrs)) ||
             (await this.handleSubjectChange(attrs))
         ) {
-            return this.removeNotification(attrs.nick, ['composing', 'paused']);
+            attrs.nick && this.removeNotification(attrs.nick, ['composing', 'paused']);
+            return;
         }
         this.setEditable(attrs, attrs.time);
 

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

@@ -6,6 +6,7 @@ import {
     getCorrectionAttributes,
     getEncryptionAttributes,
     getErrorAttributes,
+    getOpenGraphMetadata,
     getOutOfBandAttributes,
     getReceiptId,
     getReferences,
@@ -180,6 +181,7 @@ export async function parseMUCMessage (stanza, chatbox, _converse) {
         getSpoilerAttributes(stanza),
         getCorrectionAttributes(stanza, original_stanza),
         getStanzaIDs(stanza, original_stanza),
+        getOpenGraphMetadata(stanza),
         getRetractionAttributes(stanza, original_stanza),
         getModerationAttributes(stanza),
         getEncryptionAttributes(stanza, _converse)

+ 11 - 9
src/headless/shared/parsers.js

@@ -126,15 +126,17 @@ export function getOpenGraphMetadata (stanza) {
     if (fastening) {
         const applies_to_id = fastening.getAttribute('id');
         const meta = sizzle(`> meta[xmlns="${Strophe.NS.XHTML}"]`, fastening);
-        return meta.reduce((acc, el) => {
-            const property = el.getAttribute('property');
-            if (property) {
-                acc[property] = decodeHTMLEntities(el.getAttribute('content') || '');
-            }
-            return acc;
-        }, {
-            'ogp_for_id': applies_to_id,
-        });
+        if (meta.length) {
+            return meta.reduce((acc, el) => {
+                const property = el.getAttribute('property');
+                if (property) {
+                    acc[property] = decodeHTMLEntities(el.getAttribute('content') || '');
+                }
+                return acc;
+            }, {
+                'ogp_for_id': applies_to_id,
+            });
+        }
     }
     return {};
 }