Add emoji autosuggest (#5053)
* Add emoji autosuggest Some credit goes to glitch-soc/mastodon#149 * Remove server-side shortcode->unicode conversion * Insert shortcode when suggestion is custom emoji * Remove remnant of server-side emojis * Update style of autosuggestions * Fix wrong emoji filenames generated in autosuggest item * Do not lazy load emoji picker, as that no longer works * Fix custom emoji autosuggest * Fix multiple "Custom" categories getting added to emoji index, only add once
This commit is contained in:
parent
66126f3021
commit
1e02ba111a
19 changed files with 133 additions and 209 deletions
|
@ -1,40 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'singleton'
|
||||
|
||||
class Emoji
|
||||
include Singleton
|
||||
|
||||
def initialize
|
||||
data = Oj.load(File.open(Rails.root.join('lib', 'assets', 'emoji.json')))
|
||||
|
||||
@map = {}
|
||||
|
||||
data.each do |_, emoji|
|
||||
keys = [emoji['shortname']] + emoji['aliases']
|
||||
unicode = codepoint_to_unicode(emoji['unicode'])
|
||||
|
||||
keys.each do |key|
|
||||
@map[key] = unicode
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def unicode(shortcode)
|
||||
@map[shortcode]
|
||||
end
|
||||
|
||||
def names
|
||||
@map.keys
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def codepoint_to_unicode(codepoint)
|
||||
if codepoint.include?('-')
|
||||
codepoint.split('-').map(&:hex).pack('U*')
|
||||
else
|
||||
[codepoint.hex].pack('U')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue