FIX: correctly render unicode in channel page title (#29653)

Before this fix we would render the emoji as text, eg: `🐱`
This commit is contained in:
Joffrey JAFFEUX 2024-11-08 09:41:14 +09:00 committed by GitHub
parent 5a23a74bbc
commit 79254c59f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 2 deletions

View File

@ -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"

View File

@ -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;

View File

@ -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}`;
}
}

View File

@ -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

View File

@ -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