mod_ogp now sends messages with type="groupchat"

This commit is contained in:
JC Brand 2021-02-22 21:27:30 +01:00
parent f158a996f4
commit ccfa00d7b8
5 changed files with 30 additions and 30 deletions

View File

@ -23,7 +23,7 @@ describe("A Groupchat Message", function () {
expect(el.textContent).toBe('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); expect(el.textContent).toBe('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
const metadata_stanza = u.toStanza(` 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"> <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:site_name" content="YouTube" />
<meta xmlns="http://www.w3.org/1999/xhtml" property="og:url" content="https://www.youtube.com/watch?v=dQw4w9WgXcQ" /> <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'); expect(el.textContent).toBe('Check out https://www.youtube.com/watch?v=dQw4w9WgXcQ and https://duckduckgo.com');
let metadata_stanza = u.toStanza(` 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"> <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:site_name" content="YouTube" />
<meta xmlns="http://www.w3.org/1999/xhtml" property="og:url" content="https://www.youtube.com/watch?v=dQw4w9WgXcQ" /> <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> </apply-to>
</message>`); </message>`);
_converse.connection._dataRecv(mock.createRequest(metadata_stanza)); _converse.connection._dataRecv(mock.createRequest(metadata_stanza));
await u.waitUntil(() => view.querySelectorAll('converse-message-unfurl').length === 1);
metadata_stanza = u.toStanza(` 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"> <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:url" content="https://duckduckgo.com/" />
<meta xmlns="http://www.w3.org/1999/xhtml" property="og:site_name" content="DuckDuckGo" /> <meta xmlns="http://www.w3.org/1999/xhtml" property="og:site_name" content="DuckDuckGo" />

View File

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

View File

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

View File

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

View File

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