don't count bio metadata against bio length on server

signup-info-prompt
Surinna Curtis 2017-06-25 22:23:53 -05:00
parent 56ca33a6d3
commit 4f36aad6e8
1 changed files with 17 additions and 1 deletions

View File

@ -60,7 +60,7 @@ class Account < ApplicationRecord
validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? }
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, length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? }
validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? }
# Timelines
has_many :stream_entries, inverse_of: :account, dependent: :destroy
@ -251,6 +251,22 @@ class Account < ApplicationRecord
self.public_key = keypair.public_key.to_pem
end
YAML_START = "---\r\n"
YAML_END = "\r\n...\r\n"
def note_length_does_not_exceed_length_limit
note_without_metadata = note
if note.start_with? YAML_START
idx = note.index YAML_END
unless idx.nil?
note_without_metadata = note[(idx + YAML_END.length) .. -1]
end
end
if note_without_metadata.mb_chars.grapheme_length > 500
errors.add(:note, "can't be longer than 500 graphemes")
end
end
def normalize_domain
return if local?