diff options
author | blackle <isabelle@blackle-mori.com> | 2017-01-12 23:54:26 -0500 |
---|---|---|
committer | blackle <isabelle@blackle-mori.com> | 2017-01-23 21:07:40 -0500 |
commit | bf0f6eb62d0f5bd1f0d8e4e2a6e9e8fd3b297b6c (patch) | |
tree | c06ebcba34c5971d564beb98aa81d5d9784ec2c7 /app/validators/status_length_validator.rb | |
parent | 1761d3f9c33f3e2e98a09906fae1a03783b54b10 (diff) |
Implement a click-to-view spoiler system
Diffstat (limited to 'app/validators/status_length_validator.rb')
-rw-r--r-- | app/validators/status_length_validator.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb new file mode 100644 index 000000000..5491d3d5f --- /dev/null +++ b/app/validators/status_length_validator.rb @@ -0,0 +1,15 @@ +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 \ No newline at end of file |