mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
FIX: Show emoji in inline oneboxes
This commit is contained in:
parent
c2db2c5c78
commit
574681dc47
7 changed files with 25 additions and 9 deletions
|
@ -230,9 +230,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def gsub_emoji_to_unicode(str)
|
def gsub_emoji_to_unicode(str)
|
||||||
if str
|
Emoji.gsub_emoji_to_unicode(str)
|
||||||
str.gsub(/:([\w\-+]*(?::t\d)?):/) { |name| Emoji.lookup_unicode($1) || name }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def application_logo_url
|
def application_logo_url
|
||||||
|
|
|
@ -2,7 +2,7 @@ module TopicsHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
def render_topic_title(topic)
|
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
|
end
|
||||||
|
|
||||||
def categories_breadcrumb(topic)
|
def categories_breadcrumb(topic)
|
||||||
|
|
|
@ -426,7 +426,7 @@ class UserNotifications < ActionMailer::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
email_opts = {
|
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,
|
topic_title_url_encoded: title ? URI.encode(title) : title,
|
||||||
message: message,
|
message: message,
|
||||||
url: post.url(without_slug: SiteSetting.private_email?),
|
url: post.url(without_slug: SiteSetting.private_email?),
|
||||||
|
|
|
@ -159,6 +159,12 @@ class Emoji
|
||||||
end.join
|
end.join
|
||||||
end
|
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)
|
def self.lookup_unicode(name)
|
||||||
@reverse_map ||= begin
|
@reverse_map ||= begin
|
||||||
map = {}
|
map = {}
|
||||||
|
|
|
@ -95,8 +95,8 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
if object.suggested_topics.try(:topics).present?
|
if object.suggested_topics.try(:topics).present?
|
||||||
result[:suggested_topics] = object.suggested_topics.topics.map do |topic|
|
result[:suggested_topics] = object.suggested_topics.topics.map do |t|
|
||||||
SuggestedTopicSerializer.new(topic, scope: scope, root: false)
|
SuggestedTopicSerializer.new(t, scope: scope, root: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def unicode_title
|
def unicode_title
|
||||||
gsub_emoji_to_unicode(object.topic.title)
|
Emoji.gsub_emoji_to_unicode(object.topic.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_pm_with_non_human_user?
|
def include_pm_with_non_human_user?
|
||||||
|
|
|
@ -26,7 +26,10 @@ class InlineOneboxer
|
||||||
|
|
||||||
# Only public topics
|
# Only public topics
|
||||||
if Guardian.new.can_see?(topic)
|
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)
|
Rails.cache.write(cache_key(url), onebox, expires_in: 1.day)
|
||||||
return onebox
|
return onebox
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,6 +53,15 @@ describe InlineOneboxer do
|
||||||
expect(InlineOneboxer.lookup(nil)).to be_nil
|
expect(InlineOneboxer.lookup(nil)).to be_nil
|
||||||
expect(InlineOneboxer.lookup("/test")).to be_nil
|
expect(InlineOneboxer.lookup("/test")).to be_nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue