diff --git a/spec/unfurls.js b/spec/unfurls.js index 73d7ff441..512169cd4 100644 --- a/spec/unfurls.js +++ b/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(` - + @@ -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(` - + @@ -84,9 +84,10 @@ describe("A Groupchat Message", function () { `); _converse.connection._dataRecv(mock.createRequest(metadata_stanza)); + await u.waitUntil(() => view.querySelectorAll('converse-message-unfurl').length === 1); metadata_stanza = u.toStanza(` - + diff --git a/src/headless/plugins/chat/model.js b/src/headless/plugins/chat/model.js index 5184256ee..92b32e648 100644 --- a/src/headless/plugins/chat/model.js +++ b/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; diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index bb226bec3..3b2f972e5 100644 --- a/src/headless/plugins/muc/muc.js +++ b/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); diff --git a/src/headless/plugins/muc/parsers.js b/src/headless/plugins/muc/parsers.js index 9b841d886..06298635b 100644 --- a/src/headless/plugins/muc/parsers.js +++ b/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) diff --git a/src/headless/shared/parsers.js b/src/headless/shared/parsers.js index e55505819..91bc12eb7 100644 --- a/src/headless/shared/parsers.js +++ b/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 {}; }