Merge pull request #713 from kmycode/upstream-20240417
Upstream 20240417
This commit is contained in:
commit
a97eb2433b
76 changed files with 835 additions and 307 deletions
|
@ -68,6 +68,7 @@ class Account < ApplicationRecord
|
|||
)
|
||||
|
||||
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
||||
DEFAULT_FIELDS_SIZE = 6
|
||||
INSTANCE_ACTOR_ID = -99
|
||||
|
||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||
|
@ -110,7 +111,7 @@ class Account < ApplicationRecord
|
|||
validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' }
|
||||
validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
|
||||
validates :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? }
|
||||
validates :fields, length: { maximum: 6 }, if: -> { local? && will_save_change_to_fields? }
|
||||
validates :fields, length: { maximum: DEFAULT_FIELDS_SIZE }, if: -> { local? && will_save_change_to_fields? }
|
||||
validates :uri, absence: true, if: :local?, on: :create
|
||||
validates :inbox_url, absence: true, if: :local?, on: :create
|
||||
validates :shared_inbox_url, absence: true, if: :local?, on: :create
|
||||
|
@ -410,8 +411,6 @@ class Account < ApplicationRecord
|
|||
self[:fields] = fields
|
||||
end
|
||||
|
||||
DEFAULT_FIELDS_SIZE = 6
|
||||
|
||||
def build_fields
|
||||
return if fields.size >= DEFAULT_FIELDS_SIZE
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class Admin::StatusFilter
|
|||
end
|
||||
|
||||
def results
|
||||
scope = @account.statuses.where(visibility: [:public, :unlisted, :public_unlisted, :login])
|
||||
scope = @account.statuses.distributable_visibility
|
||||
|
||||
params.each do |key, value|
|
||||
next if IGNORED_PARAMS.include?(key.to_s)
|
||||
|
|
|
@ -62,7 +62,7 @@ class Announcement < ApplicationRecord
|
|||
@statuses ||= if status_ids.nil?
|
||||
[]
|
||||
else
|
||||
Status.where(id: status_ids, visibility: [:public, :unlisted, :public_unlisted])
|
||||
Status.where(id: status_ids).distributable_visibility_for_anonymous
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module Status::ThreadingConcern
|
|||
end
|
||||
|
||||
def self_replies(limit)
|
||||
account.statuses.where(in_reply_to_id: id, visibility: [:public, :unlisted, :public_unlisted, :login]).reorder(id: :asc).limit(limit)
|
||||
account.statuses.distributable_visibility.where(in_reply_to_id: id).reorder(id: :asc).limit(limit)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -46,6 +46,7 @@ class CustomFilter < ApplicationRecord
|
|||
validate :context_must_be_valid
|
||||
|
||||
normalizes :context, with: ->(context) { context.map(&:strip).filter_map(&:presence) }
|
||||
scope :unexpired, -> { where(expires_at: nil).or where.not(expires_at: ..Time.zone.now) }
|
||||
|
||||
before_save :prepare_cache_invalidation!
|
||||
before_destroy :prepare_cache_invalidation!
|
||||
|
@ -78,14 +79,16 @@ class CustomFilter < ApplicationRecord
|
|||
active_filters = Rails.cache.fetch("filters:v3:#{account_id}") do
|
||||
filters_hash = {}
|
||||
|
||||
scope = CustomFilterKeyword.includes(:custom_filter).where(custom_filter: { account_id: account_id }).where(Arel.sql('expires_at IS NULL OR expires_at > NOW()'))
|
||||
scope = CustomFilterKeyword.left_outer_joins(:custom_filter).merge(unexpired.where(account_id: account_id))
|
||||
|
||||
scope.to_a.group_by(&:custom_filter).each do |filter, keywords|
|
||||
keywords.map!(&:to_regex)
|
||||
|
||||
filters_hash[filter.id] = { keywords: Regexp.union(keywords), filter: filter }
|
||||
end.to_h
|
||||
|
||||
scope = CustomFilterStatus.includes(:custom_filter).where(custom_filter: { account_id: account_id }).where(Arel.sql('expires_at IS NULL OR expires_at > NOW()'))
|
||||
scope = CustomFilterStatus.left_outer_joins(:custom_filter).merge(unexpired.where(account_id: account_id))
|
||||
|
||||
scope.to_a.group_by(&:custom_filter).each do |filter, statuses|
|
||||
filters_hash[filter.id] ||= { filter: filter }
|
||||
filters_hash[filter.id].merge!(status_ids: statuses.map(&:status_id))
|
||||
|
|
|
@ -74,6 +74,6 @@ class FeaturedTag < ApplicationRecord
|
|||
end
|
||||
|
||||
def visible_tagged_account_statuses
|
||||
account.statuses.where(visibility: %i(public unlisted public_unlisted login)).tagged_with(tag)
|
||||
account.statuses.distributable_visibility.tagged_with(tag)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -154,6 +154,9 @@ class Status < ApplicationRecord
|
|||
where('NOT EXISTS (SELECT * FROM statuses_tags forbidden WHERE forbidden.status_id = statuses.id AND forbidden.tag_id IN (?))', tag_ids)
|
||||
}
|
||||
scope :unset_searchability, -> { where(searchability: nil, reblog_of_id: nil) }
|
||||
scope :distributable_visibility, -> { where(visibility: %i(public public_unlisted login unlisted)) }
|
||||
scope :distributable_visibility_for_anonymous, -> { where(visibility: %i(public public_unlisted unlisted)) }
|
||||
scope :list_eligible_visibility, -> { where(visibility: %i(public public_unlisted login unlisted private)) }
|
||||
|
||||
after_create_commit :trigger_create_webhooks
|
||||
after_update_commit :trigger_update_webhooks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue