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