This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2017-01-24 15:49:08 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusLengthValidator < ActiveModel::Validator
|
2017-05-28 17:09:12 -07:00
|
|
|
MAX_CHARS = 512
|
2017-01-24 15:49:08 -08:00
|
|
|
|
|
|
|
def validate(status)
|
|
|
|
return unless status.local? && !status.reblog?
|
2017-06-19 02:31:14 -07: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 15:49:08 -08:00
|
|
|
end
|
|
|
|
end
|