2014-12-22 19:12:26 -05:00
|
|
|
require 'enum_site_setting'
|
|
|
|
|
|
|
|
class EmojiSetSiteSetting < EnumSiteSetting
|
|
|
|
|
|
|
|
# fix the URLs when changing the site setting
|
|
|
|
DiscourseEvent.on(:site_setting_saved) do |site_setting|
|
2016-07-25 12:11:36 -04:00
|
|
|
if site_setting.name.to_s == "emoji_set" && site_setting.value_changed?
|
2014-12-22 19:55:13 -05:00
|
|
|
Emoji.clear_cache
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
previous_value = site_setting.attribute_in_database(:value) || SiteSetting.defaults[:emoji_set]
|
2015-01-07 11:54:09 -05:00
|
|
|
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
|
2018-06-19 02:13:14 -04:00
|
|
|
DB.exec("UPDATE posts SET cooked = REPLACE(cooked, :before, :after) WHERE cooked LIKE :like",
|
2014-12-22 19:12:26 -05:00
|
|
|
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 ||= [
|
2016-07-22 15:27:51 -04:00
|
|
|
{ name: 'emoji_set.apple_international', value: 'apple' },
|
|
|
|
{ name: 'emoji_set.google', value: 'google' },
|
|
|
|
{ name: 'emoji_set.twitter', value: 'twitter' },
|
|
|
|
{ name: 'emoji_set.emoji_one', value: 'emoji_one' },
|
2017-07-04 08:08:47 -04:00
|
|
|
{ name: 'emoji_set.win10', value: 'win10' },
|
2017-07-06 03:05:15 -04:00
|
|
|
{ name: 'emoji_set.google_classic', value: 'google_classic' },
|
2017-07-04 08:08:47 -04:00
|
|
|
{ name: 'emoji_set.facebook_messenger', value: 'facebook_messenger' },
|
2014-12-22 19:12:26 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.translate_names?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|