A platform for community discussion. Free, open, simple.
FIX: correctly render unicode in channel page title (#29653)
Joffrey JAFFEUX79254c59f989
diff --git a/plugins/chat/app/serializers/chat/channel_serializer.rb b/plugins/chat/app/serializers/chat/channel_serializer.rbindex c0193a17b12..9e8b6c8d399 100644--- a/plugins/chat/app/serializers/chat/channel_serializer.rb+++ b/plugins/chat/app/serializers/chat/channel_serializer.rb@@ -11,6 +11,7 @@ module Chat:chatable_url,:description,:title,+ :unicode_title,:slug,:status,:archive_failed,@@ -53,6 +54,10 @@ module Chatobject.name || object.title(scope.user)end+ def unicode_title+ Emoji.gsub_emoji_to_unicode(title)+ end+def chatablecase object.chatable_typewhen "Category"diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.jsindex 3d95f5e4ecb..209941f5bc5 100644--- a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js+++ b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js@@ -87,6 +87,7 @@ export default class ChatChannel {this.membershipsCount = args.memberships_count;this.slug = args.slug;this.title = args.title;+ this.unicodeTitle = args.unicode_title;this.status = args.status;this.description = args.description;this.threadingEnabled = args.threading_enabled;diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.jsindex b363d3c146d..f2350858c03 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-decorator.js@@ -15,10 +15,12 @@ export default function withChatChannel(extendedClass) {return;}+ const title = this.currentModel.unicodeTitle || this.currentModel.title;+if (this.currentModel.isDirectMessageChannel) {- return `${this.currentModel.title}`;+ return `${title}`;} else {- return `#${this.currentModel.title}`;+ return `#${title}`;}}diff --git a/plugins/chat/spec/serializer/chat/channel_serializer_spec.rb b/plugins/chat/spec/serializer/chat/channel_serializer_spec.rbindex cce759adc4a..f995c5f8066 100644--- a/plugins/chat/spec/serializer/chat/channel_serializer_spec.rb+++ b/plugins/chat/spec/serializer/chat/channel_serializer_spec.rb@@ -113,4 +113,10 @@ describe Chat::ChannelSerializer doendendend++ it "has a unicode_title" do+ chat_channel.update!(name: ":cat: Cats")++ expect(serializer.as_json[:unicode_title]).to eq("🐱 Cats")+ endenddiff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex 253143146af..f0b13cd7d91 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -419,4 +419,11 @@ RSpec.describe "Chat channel", type: :system do)endend++ it "renders emojis in page title" do+ channel_1.update!(name: ":dog: Dogs")+ chat_page.visit_channel(channel_1)++ expect(page).to have_title("#🐶 Dogs - Chat - Discourse")+ endend