discourse/app/models/emoji_set_site_setting.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2014-12-22 19:12:26 -05:00
require 'enum_site_setting'
class EmojiSetSiteSetting < EnumSiteSetting
NAME = :emoji_set
2014-12-22 19:12:26 -05:00
# fix the URLs when changing the site setting
DiscourseEvent.on(:site_setting_saved) do |site_setting|
if site_setting.name == NAME && site_setting.value_changed?
2014-12-22 19:55:13 -05:00
Emoji.clear_cache
previous_value = site_setting.value_was || SiteSetting.defaults[NAME]
before = "/images/emoji/#{previous_value}/"
2014-12-22 19:12:26 -05:00
after = "/images/emoji/#{site_setting.value}/"
Scheduler::Defer.later("Fix Emoji Links") do
Post.exec_sql("UPDATE posts SET cooked = REPLACE(cooked, :before, :after) WHERE cooked LIKE :like",
before: before,
after: after,
like: "%#{before}%"
)
end
end
end
def self.valid_value?(val)
values.any? { |v| v[:value] == val.to_s }
end
def self.values
@values ||= [
{ name: 'apple_international', value: 'apple' },
{ name: 'google', value: 'google' },
{ name: 'twitter', value: 'twitter' },
{ name: 'emoji_one', value: 'emoji_one' },
]
end
def self.translate_names?
true
end
end