diff --git a/plugins/chat/app/serializers/chat/channel_serializer.rb b/plugins/chat/app/serializers/chat/channel_serializer.rb index 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 Chat object.name || object.title(scope.user) end + def unicode_title + Emoji.gsub_emoji_to_unicode(title) + end + def chatable case object.chatable_type when "Category" diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js index 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.js index 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.rb index 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 do end end end + + it "has a unicode_title" do + chat_channel.update!(name: ":cat: Cats") + + expect(serializer.as_json[:unicode_title]).to eq("🐱 Cats") + end end diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rb index 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 ) end end + + 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") + end end