diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 36 | ||||
-rw-r--r-- | app/models/concerns/status_threading_concern.rb | 2 | ||||
-rw-r--r-- | app/models/custom_filter.rb | 2 | ||||
-rw-r--r-- | app/models/home_feed.rb | 5 | ||||
-rw-r--r-- | app/models/list_feed.rb | 3 | ||||
-rw-r--r-- | app/models/notification.rb | 2 | ||||
-rw-r--r-- | app/models/poll.rb | 10 | ||||
-rw-r--r-- | app/models/public_feed.rb | 26 | ||||
-rw-r--r-- | app/models/status.rb | 4 | ||||
-rw-r--r-- | app/models/tag_feed.rb | 11 |
10 files changed, 47 insertions, 54 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index f6aba74c6..15bd8a917 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -387,15 +387,17 @@ class Account < ApplicationRecord end class Field < ActiveModelSerializers::Model - attributes :name, :value, :verified_at, :account, :errors + attributes :name, :value, :verified_at, :account def initialize(account, attributes) - @account = account - @attributes = attributes - @name = attributes['name'].strip[0, string_limit] - @value = attributes['value'].strip[0, string_limit] - @verified_at = attributes['verified_at']&.to_datetime - @errors = {} + @original_field = attributes + string_limit = account.local? ? 255 : 2047 + super( + account: account, + name: attributes['name'].strip[0, string_limit], + value: attributes['value'].strip[0, string_limit], + verified_at: attributes['verified_at']&.to_datetime, + ) end def verified? @@ -417,22 +419,12 @@ class Account < ApplicationRecord end def mark_verified! - @verified_at = Time.now.utc - @attributes['verified_at'] = @verified_at + self.verified_at = Time.now.utc + @original_field['verified_at'] = verified_at end def to_h - { name: @name, value: @value, verified_at: @verified_at } - end - - private - - def string_limit - if account.local? - 255 - else - 2047 - end + { name: name, value: value, verified_at: verified_at } end end @@ -518,7 +510,7 @@ class Account < ApplicationRecord def from_text(text) return [] if text.blank? - text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.map do |(username, domain)| + text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.filter_map do |(username, domain)| domain = begin if TagManager.instance.local_domain?(domain) nil @@ -527,7 +519,7 @@ class Account < ApplicationRecord end end EntityCache.instance.mention(username, domain) - end.compact + end end private diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb index a0ead1995..5c04108e4 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status_threading_concern.rb @@ -83,7 +83,7 @@ module StatusThreadingConcern def find_statuses_from_tree_path(ids, account, promote: false) statuses = Status.with_accounts(ids).to_a account_ids = statuses.map(&:account_id).uniq - domains = statuses.map(&:account_domain).compact.uniq + domains = statuses.filter_map(&:account_domain).uniq relations = relations_map_for_account(account, account_ids, domains) statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? } diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index 8df8a4fbf..9d0f3729b 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -46,7 +46,7 @@ class CustomFilter < ApplicationRecord private def clean_up_contexts - self.context = Array(context).map(&:strip).map(&:presence).compact + self.context = Array(context).map(&:strip).filter_map(&:presence) end def remove_cache diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index 0fe9dae46..d6ebb5fa6 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -2,12 +2,11 @@ class HomeFeed < Feed def initialize(account) - @type = :home - @id = account.id @account = account + super(:home, account.id) end def regenerating? - redis.exists?("account:#{@id}:regeneration") + redis.exists?("account:#{@account.id}:regeneration") end end diff --git a/app/models/list_feed.rb b/app/models/list_feed.rb index f371e4ed9..47b9281b8 100644 --- a/app/models/list_feed.rb +++ b/app/models/list_feed.rb @@ -2,7 +2,6 @@ class ListFeed < Feed def initialize(list) - @type = :list - @id = list.id + super(:list, list.id) end end diff --git a/app/models/notification.rb b/app/models/notification.rb index e83123c97..b6db37d6d 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -92,7 +92,7 @@ class Notification < ApplicationRecord end def reload_stale_associations!(cached_items) - account_ids = (cached_items.map(&:from_account_id) + cached_items.map { |item| item.target_status&.account_id }.compact).uniq + account_ids = (cached_items.map(&:from_account_id) + cached_items.filter_map { |item| item.target_status&.account_id }).uniq return if account_ids.empty? diff --git a/app/models/poll.rb b/app/models/poll.rb index e1ca55252..d2a17277b 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -73,10 +73,12 @@ class Poll < ApplicationRecord attributes :id, :title, :votes_count, :poll def initialize(poll, id, title, votes_count) - @poll = poll - @id = id - @title = title - @votes_count = votes_count + super( + poll: poll, + id: id, + title: title, + votes_count: votes_count, + ) end end diff --git a/app/models/public_feed.rb b/app/models/public_feed.rb index 2839da5cb..2528ef1b6 100644 --- a/app/models/public_feed.rb +++ b/app/models/public_feed.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class PublicFeed < Feed +class PublicFeed # @param [Account] account # @param [Hash] options # @option [Boolean] :with_replies @@ -35,36 +35,38 @@ class PublicFeed < Feed private + attr_reader :account, :options + def allow_local_only? - local_account? && (local_only? || @options[:allow_local_only]) + local_account? && (local_only? || options[:allow_local_only]) end def with_reblogs? - @options[:with_reblogs] + options[:with_reblogs] end def with_replies? - @options[:with_replies] + options[:with_replies] end def local_only? - @options[:local] + options[:local] end def remote_only? - @options[:remote] + options[:remote] end def account? - @account.present? + account.present? end def local_account? - @account&.local? + account&.local? end def media_only? - @options[:only_media] + options[:only_media] end def public_scope @@ -96,9 +98,9 @@ class PublicFeed < Feed end def account_filters_scope - Status.not_excluded_by_account(@account).tap do |scope| - scope.merge!(Status.not_domain_blocked_by_account(@account)) unless local_only? - scope.merge!(Status.in_chosen_languages(@account)) if @account.chosen_languages.present? + Status.not_excluded_by_account(account).tap do |scope| + scope.merge!(Status.not_domain_blocked_by_account(account)) unless local_only? + scope.merge!(Status.in_chosen_languages(account)) if account.chosen_languages.present? end end end diff --git a/app/models/status.rb b/app/models/status.rb index 0d15304b6..766c13a40 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -387,7 +387,7 @@ class Status < ApplicationRecord def from_text(text) return [] if text.blank? - text.scan(FetchLinkCardService::URL_PATTERN).map(&:first).uniq.map do |url| + text.scan(FetchLinkCardService::URL_PATTERN).map(&:first).uniq.filter_map do |url| status = begin if TagManager.instance.local_url?(url) ActivityPub::TagManager.instance.uri_to_resource(url, Status) @@ -396,7 +396,7 @@ class Status < ApplicationRecord end end status&.distributable? ? status : nil - end.compact + end end end diff --git a/app/models/tag_feed.rb b/app/models/tag_feed.rb index a7d583a7e..fbbdbaae2 100644 --- a/app/models/tag_feed.rb +++ b/app/models/tag_feed.rb @@ -13,9 +13,8 @@ class TagFeed < PublicFeed # @option [Boolean] :remote # @option [Boolean] :only_media def initialize(tag, account, options = {}) - @tag = tag - @account = account - @options = options + @tag = tag + super(account, options) end # @param [Integer] limit @@ -41,15 +40,15 @@ class TagFeed < PublicFeed private def tagged_with_any_scope - Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(@options[:any]))) + Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(options[:any]))) end def tagged_with_all_scope - Status.group(:id).tagged_with_all(tags_for(@options[:all])) + Status.group(:id).tagged_with_all(tags_for(options[:all])) end def tagged_with_none_scope - Status.group(:id).tagged_with_none(tags_for(@options[:none])) + Status.group(:id).tagged_with_none(tags_for(options[:none])) end def tags_for(names) |