mirror of https://github.com/mastodon/mastodon
Instead of using spoiler boolean and spoiler_text, simply check for non-blank spoiler_text
Federate spoiler_text using warning attribute on <content /> instead of a <category term="spoiler" /> Clean up schema file from accidental development migrationspull/524/head
parent
f8da0dd490
commit
999cde94a6
@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class StatusLengthValidator < ActiveModel::Validator
|
||||
MAX_CHARS = 500
|
||||
|
||||
def validate(status)
|
||||
return unless status.local? && !status.reblog?
|
||||
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: MAX_CHARS)) if [status.text, status.spoiler_text].join.length > MAX_CHARS
|
||||
end
|
||||
end
|
@ -1,15 +0,0 @@
|
||||
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
|
@ -1,5 +0,0 @@
|
||||
class AddSpoilerToStatuses < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :statuses, :spoiler, :boolean, default: false
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue