diff --git a/CHANGES.md b/CHANGES.md index 5401e2277..e404c831e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ - New configuration setting: [show_tab_notifications](https://conversejs.org/docs/html/configuration.html#show-tab-notifications) - New configuration setting: [muc_clear_messages_on_leave](https://conversejs.org/docs/html/configuration.html#muc-clear-messages-on-leave) - New configuration setting: [send_chat_markers](https://conversejs.org/docs/html/configuration.html#send-chat-markers) +- New configuration setting: [muc_show_ogp_unfurls](https://conversejs.org/docs/html/configuration.html#muc-show-ogp-unfurls) - #1823: New config options [mam_request_all_pages](https://conversejs.org/docs/html/configuration.html#mam-request-all-pages) - Use the MUC stanza id when sending XEP-0333 markers - Add support for rendering unfurls via [mod_ogp](https://modules.prosody.im/mod_ogp.html) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index db4b5c1f1..8b036896f 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -1471,6 +1471,20 @@ a nickname configured for it), you'll see the message history (if the server supports `XEP-0313 Message Archive Management `_) and the nickname form at the bottom. +muc_show_ogp_unfurls +-------------------- + +* Default: ``true`` + +Supports showing extra metadata (picture and description) for URLs contained in +groupchat messages. + +The metadat must come from the MUC itself, metadata sent from participants +themselves will not be shown. + +For Prosody XMPP server, `mod_ogp `_ can be used. + + muc_subscribe_to_rai -------------------- diff --git a/spec/unfurls.js b/spec/unfurls.js index 8d4b7741e..d9a12befb 100644 --- a/spec/unfurls.js +++ b/spec/unfurls.js @@ -129,15 +129,7 @@ describe("A Groupchat Message", function () { - - - - - - - - `); _converse.connection._dataRecv(mock.createRequest(metadata_stanza)); @@ -175,15 +167,48 @@ describe("A Groupchat Message", function () { - - - - - - - - + + `); + _converse.connection._dataRecv(mock.createRequest(metadata_stanza)); + + await u.waitUntil(() => view.model.handleMetadataFastening.calls.count()); + expect(view.model.handleMetadataFastening.calls.first().returnValue).toBe(false); + expect(view.querySelector('converse-message-unfurl')).toBe(null); + done(); + })); + + it("will not render an unfurl based on OGP data if muc_show_ogp_unfurls is false", + mock.initConverse(['chatBoxesFetched'], + {'muc_show_ogp_unfurls': false}, + async function (done, _converse) { + const nick = 'romeo'; + const muc_jid = 'lounge@montague.lit'; + await mock.openAndEnterChatRoom(_converse, muc_jid, nick); + const view = _converse.api.chatviews.get(muc_jid); + + const message_stanza = u.toStanza(` + + https://www.youtube.com/watch?v=dQw4w9WgXcQ + + + + + `); + _converse.connection._dataRecv(mock.createRequest(message_stanza)); + const el = await u.waitUntil(() => view.querySelector('.chat-msg__text')); + expect(el.textContent).toBe('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); + + spyOn(view.model, 'handleMetadataFastening').and.callThrough(); + + const metadata_stanza = u.toStanza(` + + + + + + + `); _converse.connection._dataRecv(mock.createRequest(metadata_stanza)); diff --git a/src/headless/plugins/muc/index.js b/src/headless/plugins/muc/index.js index ecc25350e..5e3499981 100644 --- a/src/headless/plugins/muc/index.js +++ b/src/headless/plugins/muc/index.js @@ -252,6 +252,7 @@ converse.plugins.add('converse-muc', { ...converse.MUC_INFO_CODES.role_changes ], 'muc_show_logs_before_join': false, + 'muc_show_ogp_unfurls': true, 'muc_subscribe_to_rai': false, }); api.promises.add(['roomsAutoJoined']); diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 7a2d54ced..7c0d83bff 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -2122,6 +2122,9 @@ const ChatRoomMixin = { }, handleMetadataFastening (attrs) { + if (!api.settings.get('muc_show_ogp_unfurls')) { + return false; + } if (attrs.ogp_for_id) { if (attrs.from !== this.get('jid')) { // For now we only allow metadata from the MUC itself and not