Merge tootsuite/master at 3023725936

This commit is contained in:
Surinna Curtis
2017-11-16 01:21:16 -06:00
230 changed files with 8548 additions and 567 deletions

View File

@ -54,6 +54,8 @@ class Account < ApplicationRecord
include Attachmentable
include Remotable
MAX_NOTE_LENGTH = 500
enum protocol: [:ostatus, :activitypub]
# Local users
@ -68,7 +70,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: 160 }, 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
@ -307,6 +309,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 > MAX_NOTE_LENGTH
errors.add(:note, "can't be longer than 500 graphemes")
end
end
def normalize_domain
return if local?