FIX: Show emoji in inline oneboxes

This commit is contained in:
Robin Ward 2017-07-21 14:24:28 -04:00
parent c2db2c5c78
commit 574681dc47
7 changed files with 25 additions and 9 deletions

View File

@ -230,9 +230,7 @@ module ApplicationHelper
end
def gsub_emoji_to_unicode(str)
if str
str.gsub(/:([\w\-+]*(?::t\d)?):/) { |name| Emoji.lookup_unicode($1) || name }
end
Emoji.gsub_emoji_to_unicode(str)
end
def application_logo_url

View File

@ -2,7 +2,7 @@ module TopicsHelper
include ApplicationHelper
def render_topic_title(topic)
link_to(gsub_emoji_to_unicode(topic.title),topic.relative_url)
link_to(Emoji.gsub_emoji_to_unicode(topic.title),topic.relative_url)
end
def categories_breadcrumb(topic)

View File

@ -426,7 +426,7 @@ class UserNotifications < ActionMailer::Base
end
email_opts = {
topic_title: gsub_emoji_to_unicode(title),
topic_title: Emoji.gsub_emoji_to_unicode(title),
topic_title_url_encoded: title ? URI.encode(title) : title,
message: message,
url: post.url(without_slug: SiteSetting.private_email?),

View File

@ -159,6 +159,12 @@ class Emoji
end.join
end
def self.gsub_emoji_to_unicode(str)
if str
str.gsub(/:([\w\-+]*(?::t\d)?):/) { |name| Emoji.lookup_unicode($1) || name }
end
end
def self.lookup_unicode(name)
@reverse_map ||= begin
map = {}

View File

@ -95,8 +95,8 @@ class TopicViewSerializer < ApplicationSerializer
end
if object.suggested_topics.try(:topics).present?
result[:suggested_topics] = object.suggested_topics.topics.map do |topic|
SuggestedTopicSerializer.new(topic, scope: scope, root: false)
result[:suggested_topics] = object.suggested_topics.topics.map do |t|
SuggestedTopicSerializer.new(t, scope: scope, root: false)
end
end
@ -277,7 +277,7 @@ class TopicViewSerializer < ApplicationSerializer
end
def unicode_title
gsub_emoji_to_unicode(object.topic.title)
Emoji.gsub_emoji_to_unicode(object.topic.title)
end
def include_pm_with_non_human_user?

View File

@ -26,7 +26,10 @@ class InlineOneboxer
# Only public topics
if Guardian.new.can_see?(topic)
onebox = { url: url, title: topic.title }
onebox = {
url: url,
title: Emoji.gsub_emoji_to_unicode(topic.title)
}
Rails.cache.write(cache_key(url), onebox, expires_in: 1.day)
return onebox
end

View File

@ -53,6 +53,15 @@ describe InlineOneboxer do
expect(InlineOneboxer.lookup(nil)).to be_nil
expect(InlineOneboxer.lookup("/test")).to be_nil
end
it "will return the fancy title" do
topic = Fabricate(:topic, title: "Hello :pizza: with an emoji")
onebox = InlineOneboxer.lookup(topic.url)
expect(onebox).to be_present
expect(onebox[:url]).to eq(topic.url)
expect(onebox[:title]).to eq("Hello 🍕 with an emoji")
end
end