diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 8 | ||||
-rw-r--r-- | app/models/status.rb | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index e6cf03fa8..f0cd7c2a5 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -88,7 +88,8 @@ class Account < ApplicationRecord validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' } validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? } validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? } - validates :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? } + validates :note, note_length: { maximum: 1024 }, if: -> { local? && will_save_change_to_note? } + validate :note_has_ten_newlines?, if: -> { local? && will_save_change_to_note? } validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? } scope :remote, -> { where.not(domain: nil) } @@ -346,7 +347,6 @@ class Account < ApplicationRecord rescue ActiveRecord::RecordInvalid self.avatar = nil self.header = nil - save! end @@ -382,6 +382,10 @@ class Account < ApplicationRecord return 'local' if local? @synchronization_uri_prefix ||= uri[/http(s?):\/\/[^\/]+\//] + end + + def note_has_ten_newlines? + errors.add(:note, 'Bio can\'t have more then 10 newlines') unless note.count("\n") <= 10 end class Field < ActiveModelSerializers::Model diff --git a/app/models/status.rb b/app/models/status.rb index b426f9d5b..5716b93d4 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -351,6 +351,14 @@ class Status < ApplicationRecord super || build_status_stat end + def has_non_mention_links? + if local? + text.match? %r{https?://\w} + else + Nokogiri::HTML.fragment(text).css('a:not(.mention)').present? + end + end + private def update_status_stat!(attrs) |