Skip to content

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

DEV: Add transformers for quote customization (#34333)

Amanda Alves Branquinho5ad758ae94cf
diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.gjs b/app/assets/javascripts/discourse/app/components/composer-editor.gjs
index 2deb3e4dc6b..55d3ce1852a 100644
--- a/app/assets/javascripts/discourse/app/components/composer-editor.gjs
+++ b/app/assets/javascripts/discourse/app/components/composer-editor.gjs
@@ -188,7 +188,12 @@ export default class ComposerEditor extends Component {
if (posts && topicId === topic.get("id")) {
const quotedPost = posts.findBy("post_number", postNumber);
if (quotedPost) {
- return tinyAvatar(quotedPost.get("avatar_template"));
+ const avatarTemplate = applyValueTransformer(
+ "composer-editor-quoted-post-avatar-template",
+ quotedPost.get("avatar_template"),
+ { post: quotedPost }
+ );
+ return tinyAvatar(avatarTemplate);
}
}
},
diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
index b814be535f7..4a78b0f087d 100644
--- a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
+++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
@@ -298,7 +298,10 @@ export default class TopicMapSummary extends Component {
<ConditionalLoadingSpinner @condition={{this.loading}}>
<PluginOutlet
@name="most-liked-replies"
- @outletArgs={{lazyHash posts=this.top3LikedPosts}}
+ @outletArgs={{lazyHash
+ posts=this.top3LikedPosts
+ postUrl=this.postUrl
+ }}
>
<ul>
{{#each this.top3LikedPosts as |post|}}
diff --git a/app/assets/javascripts/discourse/app/lib/transformer/registry.js b/app/assets/javascripts/discourse/app/lib/transformer/registry.js
index ef610d9eb3c..72a72ac777e 100644
--- a/app/assets/javascripts/discourse/app/lib/transformer/registry.js
+++ b/app/assets/javascripts/discourse/app/lib/transformer/registry.js
@@ -17,7 +17,10 @@ export const VALUE_TRANSFORMERS = Object.freeze([
"category-description-text",
"category-display-name",
"category-text-color",
+ "composer-editor-quoted-post-avatar-template",
"composer-editor-reply-placeholder",
+ "composer-reply-options-user-link-name",
+ "composer-reply-options-user-avatar-template",
"composer-save-button-label",
"composer-service-cannot-submit-post",
"create-topic-label",
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index 6f9de3f22a7..8c5c47f2c06 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -14,6 +14,7 @@ import discourseComputed from "discourse/lib/decorators";
import deprecated from "discourse/lib/deprecated";
import { QUOTE_REGEXP } from "discourse/lib/quote";
import { prioritizeNameFallback } from "discourse/lib/settings";
+import { applyValueTransformer } from "discourse/lib/transformer";
import { emailValid, escapeExpression } from "discourse/lib/utilities";
import Category from "discourse/models/category";
import Draft from "discourse/models/draft";
@@ -462,7 +463,12 @@ export default class Composer extends RestModel {
if (post) {
options.label = i18n(`post.${action}`);
- options.userAvatar = tinyAvatar(post.avatar_template);
+ const avatarTemplate = applyValueTransformer(
+ "composer-reply-options-user-avatar-template",
+ post.avatar_template,
+ { post }
+ );
+ options.userAvatar = tinyAvatar(avatarTemplate);
if (this.site.desktopView) {
const originalUserName = post.get("reply_to_user.username");
@@ -484,7 +490,12 @@ export default class Composer extends RestModel {
anchor: i18n("post.post_number", { number: postNumber }),
};
- const name = prioritizeNameFallback(post.name, post.username);
+ const namePrioritized = prioritizeNameFallback(post.name, post.username);
+ const name = applyValueTransformer(
+ "composer-reply-options-user-link-name",
+ namePrioritized,
+ { post }
+ );
options.userLink = {
href: `${topic.url}/${postNumber}`,
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
index 0056d74a494..8e7cd500d72 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
@@ -1683,6 +1683,70 @@ import { i18n } from "discourse-i18n";
.dom(`button[title="${expectedName}"]`)
.exists("custom button is displayed for new topic");
});
+
+ test("modified name when replying to a post", async function (assert) {
+ withPluginApi((api) => {
+ api.registerValueTransformer(
+ "composer-reply-options-user-link-name",
+ () => {
+ return "NewNameHere";
+ }
+ );
+ });
+
+ await visit("/t/34");
+ await click("article#post_3 button.reply");
+
+ assert.dom(".reply-details .user-link").hasText("NewNameHere");
+ });
+
+ test("modified avatar when replying to a post", async function (assert) {
+ withPluginApi((api) => {
+ api.registerValueTransformer(
+ "composer-reply-options-user-avatar-template",
+ () => {
+ return "/images/avatar.png?size={size}";
+ }
+ );
+ });
+
+ await visit("/t/34");
+ await click("article#post_3 button.reply");
+
+ assert
+ .dom(".reply-details .action-title img")
+ .hasAttribute(
+ "src",
+ /\/images\/avatar\.png/,
+ "Reply avatar can be customized"
+ );
+ });
+
+ test("modified avatar in quote", async function (assert) {
+ withPluginApi((api) => {
+ api.registerValueTransformer(
+ "composer-editor-quoted-post-avatar-template",
+ () => {
+ return "/images/custom-quote-avatar.png?size={size}";
+ }
+ );
+ });
+
+ await visit("/t/34");
+ await click("article#post_3 button.reply");
+ await fillIn(
+ ".d-editor-input",
+ '[quote="charlie, post:1, topic:34"]\noriginal post content\n[/quote]'
+ );
+
+ assert
+ .dom(".d-editor-preview .quote .title img")
+ .hasAttribute(
+ "src",
+ /\/images\/custom-quote-avatar\.png/,
+ "Quote avatar can be customized"
+ );
+ });
}
);
});