Skip to content

A platform for community discussion. Free, open, simple.

FIX: Load composer preview oneboxes in the composed topic's context (#44716)

Renato Atilio125f5e21c7d0
diff --git a/frontend/discourse/app/components/composer-editor.gjs b/frontend/discourse/app/components/composer-editor.gjs
index 63301a4df37..97bc31cfb5d 100644
--- a/frontend/discourse/app/components/composer-editor.gjs
+++ b/frontend/discourse/app/components/composer-editor.gjs
@@ -672,8 +672,8 @@ export default class ComposerEditor extends Component {
const loaded = loadOneboxes(
preview,
ajax,
- this.get("composer.topic.id"),
- this.get("composer.category.id"),
+ this.get("composer.model.topic.id"),
+ this.get("composer.model.category.id"),
this.siteSettings.max_oneboxes_per_post,
refresh,
false,
diff --git a/frontend/discourse/app/lib/load-oneboxes.js b/frontend/discourse/app/lib/load-oneboxes.js
index 914366ad992..be810aa801d 100644
--- a/frontend/discourse/app/lib/load-oneboxes.js
+++ b/frontend/discourse/app/lib/load-oneboxes.js
@@ -64,11 +64,7 @@ export function loadOneboxes(
}
function _loadInlineOneboxes(inline, ajax, topicId, categoryId, onLoad) {
- applyInlineOneboxes(inline, ajax, {
- categoryId: topicId,
- topicId: categoryId,
- onLoad,
- });
+ applyInlineOneboxes(inline, ajax, { categoryId, topicId, onLoad });
}
function _loadOneboxes({
diff --git a/frontend/discourse/tests/acceptance/composer-onebox-test.js b/frontend/discourse/tests/acceptance/composer-onebox-test.js
index 8a53c9bb9e0..ec5bcf5b199 100644
--- a/frontend/discourse/tests/acceptance/composer-onebox-test.js
+++ b/frontend/discourse/tests/acceptance/composer-onebox-test.js
@@ -87,10 +87,12 @@ acceptance("Composer - Inline Onebox", function (needs) {
});
let requestsCount;
+ let requestParams;
needs.pretender((server, helper) => {
- server.get("/inline-onebox", () => {
+ server.get("/inline-onebox", (request) => {
++requestsCount;
+ requestParams = request.queryParams;
return helper.response({ "inline-oneboxes": [] });
});
});
@@ -117,4 +119,14 @@ acceptance("Composer - Inline Onebox", function (needs) {
'<p>Test <a href="http://www.example.com/page" tabindex="-1">www.example.com/page</a> Test</p>'
);
});
+
+ test("requests titles in the context of the composed topic", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("#topic-footer-buttons .btn.create");
+ await fillIn(".d-editor-input", `Test www.example.com/page`);
+
+ const { model } = this.owner.lookup("service:composer");
+ assert.strictEqual(requestParams.topic_id, String(model.topic.id));
+ assert.strictEqual(requestParams.category_id, String(model.category.id));
+ });
});
diff --git a/frontend/discourse/tests/helpers/qunit-helpers.js b/frontend/discourse/tests/helpers/qunit-helpers.js
index 7fb96674d7c..f0881f5df1a 100644
--- a/frontend/discourse/tests/helpers/qunit-helpers.js
+++ b/frontend/discourse/tests/helpers/qunit-helpers.js
@@ -11,6 +11,7 @@ import {
import { isEmpty } from "@ember/utils";
import { setupApplicationTest } from "ember-qunit";
import $ from "jquery";
+import { resetInlineOneboxCache } from "pretty-text/inline-oneboxer";
import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
import QUnit, { module, test } from "qunit";
import sinon from "sinon";
@@ -232,6 +233,7 @@ export function testCleanup(container, app) {
resetPluginOutletDecorators();
resetUsernameDecorators();
resetOneboxCache();
+ resetInlineOneboxCache();
resetCustomPostMessageCallbacks();
resetUserSearchCache();
resetHighestReadCache();
diff --git a/frontend/pretty-text/addon/inline-oneboxer.js b/frontend/pretty-text/addon/inline-oneboxer.js
index 7337b5494cf..812f5d90c60 100644
--- a/frontend/pretty-text/addon/inline-oneboxer.js
+++ b/frontend/pretty-text/addon/inline-oneboxer.js
@@ -70,3 +70,7 @@ export function applyCachedInlineOnebox(url, onebox) {
export function deleteCachedInlineOnebox(url) {
return delete _cache[url];
}
+
+export function resetInlineOneboxCache() {
+ Object.keys(_cache).forEach((url) => delete _cache[url]);
+}