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');
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" />

View File

@ -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,21 +488,17 @@ const ChatBox = ModelWithContact.extend({
return false;
},
handleMetadataFastening (stanza) {
const attrs = getOpenGraphMetadata(stanza);
if (attrs.ogp_for_id) {
handleMetadataFastening (attrs) {
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));
const list = [...(message.get('ogp_metadata') || []), pick(attrs, METADATA_ATTRIBUTES)];
message.save('ogp_metadata', list);
return true;
} else {
return false;
}
}
}
return false;
},

View File

@ -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);

View File

@ -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)

View File

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