2017-01-24 17:49:08 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusLengthValidator < ActiveModel::Validator
|
2017-05-28 19:09:12 -05:00
|
|
|
MAX_CHARS = 512
|
2017-01-24 17:49:08 -06:00
|
|
|
|
|
|
|
def validate(status)
|
|
|
|
return unless status.local? && !status.reblog?
|
2017-06-19 04:31:14 -05: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 17:49:08 -06:00
|
|
|
end
|
|
|
|
end
|