diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-05-09 17:43:30 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-05-10 00:03:28 +0200 |
commit | 1c9c0167b7ea7dd03ef233a085adc0a6ef1b2527 (patch) | |
tree | ccfcb53c4ddb61d7ef3158d29403ff7cd6516e55 /app/models | |
parent | 143878d9dadd03347c54c9261b9bc754a1d0f5bc (diff) | |
parent | ac788ad47e32a3cf84a46ac87f84f376185cdad4 (diff) |
Merge branch 'master' into glitch-soc/master
Conflicts: app/models/account.rb app/views/accounts/_header.html.haml
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 30 | ||||
-rw-r--r-- | app/models/user.rb | 2 |
2 files changed, 25 insertions, 7 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index c1ce1e99e..06c190446 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -45,6 +45,7 @@ # moved_to_account_id :bigint(8) # featured_collection_url :string # fields :jsonb +# actor_type :string # class Account < ApplicationRecord @@ -76,6 +77,7 @@ class Account < ApplicationRecord validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? } validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? } validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? } + validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? } # Timelines has_many :stream_entries, inverse_of: :account, dependent: :destroy @@ -151,6 +153,16 @@ class Account < ApplicationRecord moved_to_account_id.present? end + def bot? + %w(Application Service).include? actor_type + end + + alias bot bot? + + def bot=(val) + self.actor_type = ActiveModel::Type::Boolean.new.cast(val) ? 'Service' : 'Person' + end + def acct local? ? username : "#{username}@#{domain}" end @@ -201,9 +213,11 @@ class Account < ApplicationRecord def fields_attributes=(attributes) fields = [] - attributes.each_value do |attr| - next if attr[:name].blank? - fields << attr + if attributes.is_a?(Hash) + attributes.each_value do |attr| + next if attr[:name].blank? + fields << attr + end end self[:fields] = fields @@ -272,8 +286,8 @@ class Account < ApplicationRecord def initialize(account, attr) @account = account - @name = attr['name'] - @value = attr['value'] + @name = attr['name'].strip[0, 255] + @value = attr['value'].strip[0, 255] @errors = {} end @@ -398,7 +412,7 @@ class Account < ApplicationRecord end def emojis - @emojis ||= CustomEmoji.from_text(note, domain) + @emojis ||= CustomEmoji.from_text(emojifiable_text, domain) end before_create :generate_keys @@ -441,4 +455,8 @@ class Account < ApplicationRecord self.domain = TagManager.instance.normalize_domain(domain) end + + def emojifiable_text + [note, display_name, fields.map(&:value)].join(' ') + end end diff --git a/app/models/user.rb b/app/models/user.rb index 24beb77b2..82d165079 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,7 +41,7 @@ class User < ApplicationRecord include Settings::Extend include Omniauthable - ACTIVE_DURATION = 14.days + ACTIVE_DURATION = 7.days devise :two_factor_authenticatable, otp_secret_encryption_key: Rails.configuration.x.otp_secret |