Implement a click-to-view spoiler system
This commit is contained in:
parent
1761d3f9c3
commit
bf0f6eb62d
18 changed files with 192 additions and 77 deletions
15
app/validators/status_length_validator.rb
Normal file
15
app/validators/status_length_validator.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue