2018-02-17 00:10:30 -05:00
|
|
|
class MaxEmojisValidator < ActiveModel::EachValidator
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
2018-03-05 09:35:24 -05:00
|
|
|
if Emoji.unicode_unescape(value).scan(/:([\w\-+]+(?::t\d)?):/).size > SiteSetting.max_emojis_in_title
|
2018-02-17 00:10:30 -05:00
|
|
|
record.errors.add(
|
|
|
|
attribute, :max_emojis,
|
|
|
|
max_emojis_count: SiteSetting.max_emojis_in_title
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|