Implement a click-to-view spoiler system
This commit is contained in:
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
|
Reference in New Issue
Block a user