FIX: unicode titles missing when visiting topic from topic list

This commit is contained in:
Sam 2017-12-21 15:20:30 +11:00
parent 8f6e2b7186
commit 081959227d
5 changed files with 20 additions and 19 deletions

View File

@ -20,7 +20,7 @@ const TopicRoute = Discourse.Route.extend({
titleToken() {
const model = this.modelFor('topic');
if (model) {
const result = model.get('unicode_title') ? model.get('unicode_title') : model.get('title'),
const result = model.get('unicode_title') || model.get('title'),
cat = model.get('category');
// Only display uncategorized in the title tag if it was renamed

View File

@ -22,10 +22,19 @@ class ListableTopicSerializer < BasicTopicSerializer
:is_warning,
:notification_level,
:bookmarked,
:liked
:liked,
:unicode_title
has_one :last_poster, serializer: BasicUserSerializer, embed: :objects
def include_unicode_title?
object.title.match?(/:[\w\-+]+:/)
end
def unicode_title
Emoji.gsub_emoji_to_unicode(object.title)
end
def highest_post_number
(scope.is_staff? && object.highest_staff_post_number) || object.highest_post_number
end

View File

@ -267,7 +267,7 @@ class TopicViewSerializer < ApplicationSerializer
end
def include_unicode_title?
!!(object.topic.title =~ /:([\w\-+]*):/)
object.topic.title.match?(/:[\w\-+]+:/)
end
def unicode_title

View File

@ -0,0 +1,8 @@
class String
# new to Ruby 2.4, fastest way of matching a string to a regex
unless method_defined? :match?
def match?(regex)
!!(self =~ regex)
end
end
end

View File

@ -1,16 +0,0 @@
class String
# A poor man's scrub, Ruby 2.1 has a much better implementation, but this will do
unless method_defined? :scrub
def scrub(replace_char = nil)
str = dup.force_encoding("utf-8")
unless str.valid_encoding?
# work around bust string with a double conversion
str.encode!("utf-16", "utf-8", invalid: :replace)
str.encode!("utf-8", "utf-16")
end
str
end
end
end