gearheads
/
mastodon
Archived
2
0
Fork 0
This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
mastodon/app/validators/status_length_validator.rb

15 lines
447 B
Ruby
Raw Normal View History

class StatusLengthValidator < ActiveModel::Validator
def validate(status)
if status.local? && !status.reblog?
combinedText = status.text
if (status.spoiler? && status.spoiler_text.present?)
combinedText = status.spoiler_text + "\n" + status.text
end
maxChars = 500
unless combinedText.length <= maxChars
status.errors[:text] << "is too long (maximum is #{maxChars})"
end
end
end
end