diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 404ed92bf42..d087594227e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -220,7 +220,7 @@ module ApplicationHelper def gsub_emoji_to_unicode(str) if str - str.gsub(/:([\w\-+]*):/) { |name| Emoji.lookup_unicode($1) || name } + str.gsub(/:([\w\-+]*(?::t\d)?):/) { |name| Emoji.lookup_unicode($1) || name } end end diff --git a/app/models/emoji.rb b/app/models/emoji.rb index 80c66b26ac2..0f0b5104404 100644 --- a/app/models/emoji.rb +++ b/app/models/emoji.rb @@ -2,6 +2,8 @@ class Emoji # update this to clear the cache EMOJI_VERSION = "v5" + FITZPATRICK_SCALE ||= [ "1f3fb", "1f3fc", "1f3fd", "1f3fe", "1f3ff" ] + include ActiveModel::SerializerSupport attr_reader :path @@ -147,8 +149,17 @@ class Emoji db['emojis'].each do |e| next if e['name'] == 'tm' + code = replacement_code(e['code']) - map[e['name']] = code if code + next unless code + + map[e['name']] = code + if Emoji.tonable_emojis.include?(e['name']) + FITZPATRICK_SCALE.each_with_index do |scale, index| + toned_code = (code.codepoints.insert(1, scale.to_i(16))).pack("U*") + map["#{e['name']}:t#{index+2}"] = toned_code + end + end end Emoji.aliases.each do |key, alias_names| diff --git a/spec/models/emoji_spec.rb b/spec/models/emoji_spec.rb index 40c214b40aa..d1b7430f760 100644 --- a/spec/models/emoji_spec.rb +++ b/spec/models/emoji_spec.rb @@ -28,4 +28,18 @@ describe Emoji do end end + describe '.lookup_unicode' do + it 'should return the emoji' do + expect(Emoji.lookup_unicode("blonde_man")).to eq("👱") + end + + it 'should return an aliased emoji' do + expect(Emoji.lookup_unicode("anger_right")).to eq("🗯") + end + + it 'should return a skin toned emoji' do + expect(Emoji.lookup_unicode("blonde_woman:t6")).to eq("👱🏿‍♀️") + end + end + end