2017-01-24 23:49:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusLengthValidator < ActiveModel::Validator
|
2017-05-29 01:09:12 +01:00
|
|
|
MAX_CHARS = 512
|
2017-01-24 23:49:08 +00:00
|
|
|
|
|
|
|
def validate(status)
|
|
|
|
return unless status.local? && !status.reblog?
|
2017-06-19 10:31:14 +01:00
|
|
|
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: MAX_CHARS)) if [status.text, status.spoiler_text].join.mb_chars.grapheme_length > MAX_CHARS
|
2017-01-24 23:49:08 +00:00
|
|
|
end
|
|
|
|
end
|