Merge remote-tracking branch 'parent/main' into upstream-20240327

This commit is contained in:
KMY 2024-03-27 12:13:55 +09:00
commit ace193fda3
75 changed files with 435 additions and 462 deletions

View file

@ -140,12 +140,13 @@ class Account < ApplicationRecord
scope :auditable, -> { where(id: Admin::ActionLog.select(:account_id).distinct) }
scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) }
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat) }
scope :by_recent_status, -> { includes(:account_stat).merge(AccountStat.order('last_status_at DESC NULLS LAST')).references(:account_stat) }
scope :by_recent_status, -> { includes(:account_stat).merge(AccountStat.by_recent_status).references(:account_stat) }
scope :by_recent_activity, -> { left_joins(:user, :account_stat).order(coalesced_activity_timestamps.desc).order(id: :desc) }
scope :popular, -> { order('account_stats.followers_count desc') }
scope :by_domain_and_subdomains, ->(domain) { where(domain: Instance.by_domain_and_subdomains(domain).select(:domain)) }
scope :not_excluded_by_account, ->(account) { where.not(id: account.excluded_from_timeline_account_ids) }
scope :not_domain_blocked_by_account, ->(account) { where(arel_table[:domain].eq(nil).or(arel_table[:domain].not_in(account.excluded_from_timeline_domains))) }
scope :dormant, -> { joins(:account_stat).merge(AccountStat.without_recent_activity) }
after_update_commit :trigger_update_webhooks

View file

@ -20,6 +20,9 @@ class AccountStat < ApplicationRecord
belongs_to :account, inverse_of: :account_stat
scope :by_recent_status, -> { order(arel_table[:last_status_at].desc.nulls_last) }
scope :without_recent_activity, -> { where(last_status_at: [nil, ...1.month.ago]) }
update_index('accounts', :account)
def following_count

View file

@ -30,14 +30,16 @@ class Admin::Import
csv_converter = lambda do |field, field_info|
case field_info.header
when '#domain', '#public_comment'
when '#domain'
field&.downcase&.strip
when '#public_comment'
field&.strip
when '#severity'
field&.strip&.to_sym
field&.downcase&.strip&.to_sym
when '#reject_media', '#reject_reports', '#obfuscate', '#reject_favourite', '#reject_send_sensitive',
'#reject_hashtag', '#reject_straight_follow', '#reject_new_follow', '#hidden', '#detect_invalid_subscription',
'#reject_reply_exclude_followers', '#reject_friend', '#block_trends'
ActiveModel::Type::Boolean.new.cast(field)
ActiveModel::Type::Boolean.new.cast(field&.downcase)
else
field
end

View file

@ -111,12 +111,14 @@ class Form::Import
csv_converter = lambda do |field, field_info|
case field_info.header
when 'Show boosts', 'Notify on new posts', 'Hide notifications'
ActiveModel::Type::Boolean.new.cast(field)
ActiveModel::Type::Boolean.new.cast(field&.downcase)
when 'Languages'
field&.split(',')&.map(&:strip)&.presence
when 'Account address'
field.strip.gsub(/\A@/, '')
when '#domain', '#uri', 'List name'
when '#domain'
field&.strip&.downcase
when '#uri', 'List name'
field.strip
else
field

View file

@ -15,5 +15,7 @@ class PreviewCardTrend < ApplicationRecord
include RankedTrend
belongs_to :preview_card
scope :allowed, -> { where(allowed: true) }
scope :not_allowed, -> { where(allowed: false) }
end

View file

@ -114,7 +114,7 @@ class RelationshipFilter
def activity_scope(value)
case value
when 'dormant'
Account.joins(:account_stat).where(account_stat: { last_status_at: [nil, ...1.month.ago] })
Account.dormant
else
raise Mastodon::InvalidParameterError, "Unknown activity: #{value}"
end

View file

@ -86,8 +86,8 @@ class Trends::Links < Trends::Base
def request_review
PreviewCardTrend.pluck('distinct language').flat_map do |language|
score_at_threshold = PreviewCardTrend.where(language: language, allowed: true).by_rank.ranked_below(options[:review_threshold]).first&.score || 0
preview_card_trends = PreviewCardTrend.where(language: language, allowed: false).joins(:preview_card)
score_at_threshold = PreviewCardTrend.where(language: language).allowed.by_rank.ranked_below(options[:review_threshold]).first&.score || 0
preview_card_trends = PreviewCardTrend.where(language: language).not_allowed.joins(:preview_card)
preview_card_trends.filter_map do |trend|
preview_card = trend.preview_card