A platform for community discussion. Free, open, simple.
FIX: Convert emoji codes in group DM channel titles (#37244)
Régis Hanolb213f9b0d2b0
diff --git a/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs b/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjsindex 07d2ef10e29..6954760dd30 100644--- a/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs@@ -52,10 +52,10 @@ export default class ChatChannelName extends Component {get channelTitle() {if (this.args.channel.isDirectMessageChannel) {- return this.args.channel.title ?? this.directMessageTitle;+ return this.args.channel.displayTitle ?? this.directMessageTitle;}- return this.args.channel.title;+ return this.args.channel.displayTitle;}get showPluginOutlet() {diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.jsindex bbe9e01bfd2..7b1a39f01a4 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js@@ -99,7 +99,7 @@ function createChannelLink(BaseCustomSidebarSectionLink, options = {}) {get text() {if (this.isDM) {if (this.channel.chatable.group) {- return this.channel.title;+ return this.channel.displayTitle;} else {const username = this.channel.escapedTitle.replaceAll("@", "");return htmlSafe(@@ -785,7 +785,7 @@ export default {get text() {if (this.channel.chatable.group) {- return this.channel.title;+ return this.channel.displayTitle;} else {const username = this.channel.escapedTitle.replaceAll("@",diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.jsindex d84b09547da..3d67f811828 100644--- a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js+++ b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js@@ -165,6 +165,10 @@ export default class ChatChannel {return escapeExpression(this.title);}+ get displayTitle() {+ return this.unicodeTitle ?? this.title;+ }+get escapedDescription() {return escapeExpression(this.description?.trim());}diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.jsindex 19eeea39487..5dcb8761d80 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.js@@ -16,7 +16,7 @@ export default function withChatChannel(extendedClass) {return;}- const title = this.currentModel.unicodeTitle || this.currentModel.title;+ const title = this.currentModel.displayTitle;if (this.currentModel.isDirectMessageChannel) {return `${title}`;diff --git a/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb b/plugins/chat/spec/system/sidebar_navigation_menu_spec.rbindex 2b156245ca0..ed9e68672ea 100644--- a/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb+++ b/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb@@ -169,6 +169,20 @@ RSpec.describe "Sidebar navigation menu", type: :system do),).to have_content("alansmith, zoesmith")end++ context "when the group DM has an emoji in the title" do+ before { dm_channel_1.update!(name: "test :heart:") }++ it "converts the emoji" do+ visit("/")++ expect(+ sidebar_page.dms_section.find(+ "a.sidebar-section-link:nth-child(1) .sidebar-section-link-content-text",+ ),+ ).to have_content("test ❤")+ end+ endendcontext "when username contains malicious content" dodiff --git a/plugins/chat/spec/system/visit_channel_spec.rb b/plugins/chat/spec/system/visit_channel_spec.rbindex 5a569f575af..86eabe11da6 100644--- a/plugins/chat/spec/system/visit_channel_spec.rb+++ b/plugins/chat/spec/system/visit_channel_spec.rb@@ -230,7 +230,7 @@ RSpec.describe "Visit channel", type: :system doFabricate(:chat_message, chat_channel: dm_channel_1, user: current_user)end- it "doesn’t ask to join it" do+ it "doesn't ask to join it" dochat.visit_channel(dm_channel_1)expect(page).to have_no_content(I18n.t("js.chat.channel_settings.join_channel"))@@ -242,7 +242,7 @@ RSpec.describe "Visit channel", type: :system doexpect(channel_page.messages).to have_message(id: message_1.id)end- context "when URL doesn’t contain slug" do+ context "when URL doesn't contain slug" doit "redirects to correct URL" dovisit("/chat/c/-/#{dm_channel_1.id}")@@ -252,6 +252,22 @@ RSpec.describe "Visit channel", type: :system doendendend++ context "when group direct message channel has an emoji in the title" do+ fab!(:other_user, :user)+ fab!(:group_dm_channel) do+ Fabricate(:direct_message_channel, users: [current_user, other_user])+ end++ before { group_dm_channel.update!(name: "test :heart:") }++ it "converts the emoji in the header" do+ chat.visit_channel(group_dm_channel)++ expect(page.find(".c-navbar__channel-title")).to have_content("test")+ expect(page.find(".c-navbar__channel-title")).to have_no_content(":heart:")+ end+ endendendend