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