diff options
author | ThibG <thib@sitedethib.com> | 2019-01-11 10:53:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-11 10:53:58 +0100 |
commit | 2cfa55185a5fc7d93a160a4e9a4730aae6725b0f (patch) | |
tree | c57169b5a3d717f4e68b8ec5d2d6e220d1456434 /app/models/account.rb | |
parent | d1da0a1086fa25f22739277fbf32ba1b3745317d (diff) | |
parent | 394525e32994e605093c87d3a9fad2a4202f3401 (diff) |
Merge pull request #885 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models/account.rb')
-rw-r--r-- | app/models/account.rb | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 722e47d65..1ee63c738 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -44,6 +44,7 @@ # fields :jsonb # actor_type :string # discoverable :boolean +# also_known_as :string is an Array # class Account < ApplicationRecord @@ -78,7 +79,7 @@ class Account < ApplicationRecord validates_with UniqueUsernameValidator, if: -> { local? && will_save_change_to_username? } validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? } validates :display_name, length: { maximum: MAX_DISPLAY_NAME_LENGTH }, if: -> { local? && will_save_change_to_display_name? } - validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? } + validates :note, note_length: { maximum: MAX_NOTE_LENGTH }, if: -> { local? && will_save_change_to_note? } validates :fields, length: { maximum: MAX_FIELDS }, if: -> { local? && will_save_change_to_fields? } scope :remote, -> { where.not(domain: nil) } @@ -232,6 +233,10 @@ class Account < ApplicationRecord end end + def also_known_as + self[:also_known_as] || [] + end + def fields (self[:fields] || []).map { |f| Field.new(self, f) } end @@ -483,22 +488,6 @@ 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 > MAX_NOTE_LENGTH - errors.add(:note, "can't be longer than 500 graphemes") - end - end - def normalize_domain return if local? |