mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Plugin Custom emoji weren't working correctly on the server side
This commit is contained in:
@ -23,19 +23,19 @@ class Emoji
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
Discourse.cache.fetch("all_emojis:#{EMOJI_VERSION}") { standard | custom }
|
Discourse.cache.fetch(cache_key("all_emojis")) { standard | custom }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.standard
|
def self.standard
|
||||||
Discourse.cache.fetch("standard_emojis:#{EMOJI_VERSION}") { load_standard }
|
Discourse.cache.fetch(cache_key("standard_emojis")) { load_standard }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.aliases
|
def self.aliases
|
||||||
Discourse.cache.fetch("aliases_emojis:#{EMOJI_VERSION}") { load_aliases }
|
Discourse.cache.fetch(cache_key("aliases_emojis")) { load_aliases }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.custom
|
def self.custom
|
||||||
Discourse.cache.fetch("custom_emojis:#{EMOJI_VERSION}") { load_custom }
|
Discourse.cache.fetch(cache_key("custom_emojis")) { load_custom }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.exists?(name)
|
def self.exists?(name)
|
||||||
@ -78,11 +78,15 @@ class Emoji
|
|||||||
Emoji[name]
|
Emoji[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.cache_key(name)
|
||||||
|
"#{name}:#{EMOJI_VERSION}:#{Plugin::CustomEmoji.cache_key}"
|
||||||
|
end
|
||||||
|
|
||||||
def self.clear_cache
|
def self.clear_cache
|
||||||
Discourse.cache.delete("custom_emojis:#{EMOJI_VERSION}")
|
Discourse.cache.delete(cache_key("custom_emojis"))
|
||||||
Discourse.cache.delete("standard_emojis:#{EMOJI_VERSION}")
|
Discourse.cache.delete(cache_key("standard_emojis"))
|
||||||
Discourse.cache.delete("aliases_emojis:#{EMOJI_VERSION}")
|
Discourse.cache.delete(cache_key("aliases_emojis"))
|
||||||
Discourse.cache.delete("all_emojis:#{EMOJI_VERSION}")
|
Discourse.cache.delete(cache_key("all_emojis"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.db_file
|
def self.db_file
|
||||||
@ -117,9 +121,20 @@ class Emoji
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.load_custom
|
def self.load_custom
|
||||||
|
result = []
|
||||||
|
|
||||||
Dir.glob(File.join(Emoji.base_directory, "*.{png,gif}"))
|
Dir.glob(File.join(Emoji.base_directory, "*.{png,gif}"))
|
||||||
.sort
|
.sort
|
||||||
.map { |emoji| Emoji.create_from_path(emoji) }
|
.each { |emoji| result << Emoji.create_from_path(emoji) }
|
||||||
|
|
||||||
|
Plugin::CustomEmoji.emojis.each do |name, url|
|
||||||
|
result << Emoji.new.tap do |e|
|
||||||
|
e.name = name
|
||||||
|
e.url = url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.base_directory
|
def self.base_directory
|
||||||
|
@ -3,6 +3,21 @@ require 'fileutils'
|
|||||||
require_dependency 'plugin/metadata'
|
require_dependency 'plugin/metadata'
|
||||||
require_dependency 'plugin/auth_provider'
|
require_dependency 'plugin/auth_provider'
|
||||||
|
|
||||||
|
class Plugin::CustomEmoji
|
||||||
|
def self.cache_key
|
||||||
|
@@cache_key ||= "plugin-emoji"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.emojis
|
||||||
|
@@emojis ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.register(name, url)
|
||||||
|
@@cache_key = Digest::SHA1.hexdigest(cache_key + name)[0..10]
|
||||||
|
emojis[name] = url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class Plugin::Instance
|
class Plugin::Instance
|
||||||
|
|
||||||
attr_accessor :path, :metadata
|
attr_accessor :path, :metadata
|
||||||
@ -17,13 +32,8 @@ class Plugin::Instance
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Memoized hash readers
|
def seed_data
|
||||||
[:seed_data, :emojis].each do |att|
|
@seed_data ||= HashWithIndifferentAccess.new({})
|
||||||
class_eval %Q{
|
|
||||||
def #{att}
|
|
||||||
@#{att} ||= HashWithIndifferentAccess.new({})
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_all(parent_path)
|
def self.find_all(parent_path)
|
||||||
@ -225,7 +235,7 @@ class Plugin::Instance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def register_emoji(name, url)
|
def register_emoji(name, url)
|
||||||
emojis[name] = url
|
Plugin::CustomEmoji.register(name, url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def automatic_assets
|
def automatic_assets
|
||||||
@ -264,29 +274,6 @@ JS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if emojis.present?
|
|
||||||
emoji_registrations = ""
|
|
||||||
emojis.each do |name, url|
|
|
||||||
emoji_registrations << "emoji.registerEmoji(#{name.inspect}, #{url.inspect});\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
js << <<~JS
|
|
||||||
define("discourse/initializers/custom-emoji",
|
|
||||||
["pretty-text/emoji", "exports"],
|
|
||||||
function(emoji, __exports__) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
__exports__["default"] = {
|
|
||||||
name: "custom-emoji",
|
|
||||||
after: "inject-objects",
|
|
||||||
initialize: function(container) {
|
|
||||||
#{emoji_registrations}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
JS
|
|
||||||
end
|
|
||||||
|
|
||||||
# Generate an IIFE for the JS
|
# Generate an IIFE for the JS
|
||||||
js = "(function(){#{js}})();" if js.present?
|
js = "(function(){#{js}})();" if js.present?
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user