FEATURE: remap emojis back for push notifications and desktop alerts
This commit is contained in:
parent
6031e692f0
commit
89daa43754
|
@ -173,6 +173,19 @@ class Emoji
|
||||||
@unicode_replacements
|
@unicode_replacements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.lookup_unicode(name)
|
||||||
|
@reverse_map ||= begin
|
||||||
|
map = {}
|
||||||
|
db['emojis'].each do |e|
|
||||||
|
next if e['name'] == 'tm'
|
||||||
|
code = replacement_code(e['code'])
|
||||||
|
map[e['name']] = code if code
|
||||||
|
end
|
||||||
|
map
|
||||||
|
end
|
||||||
|
@reverse_map[name]
|
||||||
|
end
|
||||||
|
|
||||||
def self.unicode_replacements_json
|
def self.unicode_replacements_json
|
||||||
@unicode_replacements_json ||= unicode_replacements.to_json
|
@unicode_replacements_json ||= unicode_replacements.to_json
|
||||||
end
|
end
|
||||||
|
|
|
@ -382,7 +382,7 @@ class PostAlerter
|
||||||
post_number: original_post.post_number,
|
post_number: original_post.post_number,
|
||||||
topic_title: original_post.topic.title,
|
topic_title: original_post.topic.title,
|
||||||
topic_id: original_post.topic.id,
|
topic_id: original_post.topic.id,
|
||||||
excerpt: original_post.excerpt(400, text_entities: true, strip_links: true),
|
excerpt: original_post.excerpt(400, text_entities: true, strip_links: true, remap_emoji: true),
|
||||||
username: original_username,
|
username: original_username,
|
||||||
post_url: post_url
|
post_url: post_url
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||||
@markdown_images = options[:markdown_images] == true
|
@markdown_images = options[:markdown_images] == true
|
||||||
@keep_newlines = options[:keep_newlines] == true
|
@keep_newlines = options[:keep_newlines] == true
|
||||||
@keep_emoji_images = options[:keep_emoji_images] == true
|
@keep_emoji_images = options[:keep_emoji_images] == true
|
||||||
|
@remap_emoji = options[:remap_emoji] == true
|
||||||
@start_excerpt = false
|
@start_excerpt = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,7 +52,11 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||||
attributes = Hash[*attributes.flatten]
|
attributes = Hash[*attributes.flatten]
|
||||||
|
|
||||||
if attributes["class"] == 'emoji'
|
if attributes["class"] == 'emoji'
|
||||||
if @keep_emoji_images
|
if @remap_emoji
|
||||||
|
title = (attributes["alt"] || "").gsub(":", "")
|
||||||
|
title = Emoji.lookup_unicode(title) || attributes["alt"]
|
||||||
|
return characters(title)
|
||||||
|
elsif @keep_emoji_images
|
||||||
return include_tag(name, attributes)
|
return include_tag(name, attributes)
|
||||||
else
|
else
|
||||||
return characters(attributes["alt"])
|
return characters(attributes["alt"])
|
||||||
|
|
|
@ -265,6 +265,11 @@ HTML
|
||||||
expect(PrettyText.excerpt(emoji_image, 100, { keep_emoji_images: true })).to match_html(emoji_image)
|
expect(PrettyText.excerpt(emoji_image, 100, { keep_emoji_images: true })).to match_html(emoji_image)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should have an option to remap emoji to code points" do
|
||||||
|
emoji_image = "I <img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'> you <img src='/images/emoji/emoji_one/heart.png?v=1' title=':unknown:' class='emoji' alt=':unknown:'> "
|
||||||
|
expect(PrettyText.excerpt(emoji_image, 100, { remap_emoji: true })).to match_html("I ❤ you :unknown:")
|
||||||
|
end
|
||||||
|
|
||||||
it "should have an option to preserve emoji codes" do
|
it "should have an option to preserve emoji codes" do
|
||||||
emoji_code = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'>"
|
emoji_code = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'>"
|
||||||
expect(PrettyText.excerpt(emoji_code, 100)).to eq(":heart:")
|
expect(PrettyText.excerpt(emoji_code, 100)).to eq(":heart:")
|
||||||
|
|
|
@ -327,7 +327,7 @@ describe PostAlerter do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "push_notification" do
|
describe "push_notification" do
|
||||||
let(:mention_post) { create_post_with_alerts(user: user, raw: 'Hello @eviltrout')}
|
let(:mention_post) { create_post_with_alerts(user: user, raw: 'Hello @eviltrout :heart:')}
|
||||||
let(:topic) { mention_post.topic }
|
let(:topic) { mention_post.topic }
|
||||||
|
|
||||||
it "correctly pushes notifications if configured correctly" do
|
it "correctly pushes notifications if configured correctly" do
|
||||||
|
@ -344,8 +344,6 @@ describe PostAlerter do
|
||||||
push_url: "https://site2.com/push")
|
push_url: "https://site2.com/push")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
body = nil
|
body = nil
|
||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
@ -368,7 +366,7 @@ describe PostAlerter do
|
||||||
'post_number' => 1,
|
'post_number' => 1,
|
||||||
'topic_title' => topic.title,
|
'topic_title' => topic.title,
|
||||||
'topic_id' => topic.id,
|
'topic_id' => topic.id,
|
||||||
'excerpt' => 'Hello @eviltrout',
|
'excerpt' => 'Hello @eviltrout ❤',
|
||||||
'username' => user.username,
|
'username' => user.username,
|
||||||
'url' => UrlHelper.absolute(mention_post.url),
|
'url' => UrlHelper.absolute(mention_post.url),
|
||||||
'client_id' => 'xxx0'
|
'client_id' => 'xxx0'
|
||||||
|
@ -378,7 +376,7 @@ describe PostAlerter do
|
||||||
'post_number' => 1,
|
'post_number' => 1,
|
||||||
'topic_title' => topic.title,
|
'topic_title' => topic.title,
|
||||||
'topic_id' => topic.id,
|
'topic_id' => topic.id,
|
||||||
'excerpt' => 'Hello @eviltrout',
|
'excerpt' => 'Hello @eviltrout ❤',
|
||||||
'username' => user.username,
|
'username' => user.username,
|
||||||
'url' => UrlHelper.absolute(mention_post.url),
|
'url' => UrlHelper.absolute(mention_post.url),
|
||||||
'client_id' => 'xxx1'
|
'client_id' => 'xxx1'
|
||||||
|
|
Loading…
Reference in New Issue