Merge branch 'main' into glitch-soc/merge-upstream
This commit is contained in:
@@ -2,12 +2,32 @@
|
||||
|
||||
class ActivityPub::Activity::Add < ActivityPub::Activity
|
||||
def perform
|
||||
return unless @json['target'].present? && value_or_id(@json['target']) == @account.featured_collection_url
|
||||
return if @json['target'].blank?
|
||||
|
||||
case value_or_id(@json['target'])
|
||||
when @account.featured_collection_url
|
||||
case @object['type']
|
||||
when 'Hashtag'
|
||||
add_featured_tags
|
||||
else
|
||||
add_featured
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_featured
|
||||
status = status_from_object
|
||||
|
||||
return unless !status.nil? && status.account_id == @account.id && !@account.pinned?(status)
|
||||
|
||||
StatusPin.create!(account: @account, status: status)
|
||||
end
|
||||
|
||||
def add_featured_tags
|
||||
name = @object['name']&.delete_prefix('#')
|
||||
|
||||
FeaturedTag.create!(account: @account, name: name) if name.present?
|
||||
end
|
||||
end
|
||||
|
@@ -2,8 +2,22 @@
|
||||
|
||||
class ActivityPub::Activity::Remove < ActivityPub::Activity
|
||||
def perform
|
||||
return unless @json['target'].present? && value_or_id(@json['target']) == @account.featured_collection_url
|
||||
return if @json['target'].blank?
|
||||
|
||||
case value_or_id(@json['target'])
|
||||
when @account.featured_collection_url
|
||||
case @object['type']
|
||||
when 'Hashtag'
|
||||
remove_featured_tags
|
||||
else
|
||||
remove_featured
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_featured
|
||||
status = status_from_uri(object_uri)
|
||||
|
||||
return unless !status.nil? && status.account_id == @account.id
|
||||
@@ -11,4 +25,13 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
||||
pin = StatusPin.find_by(account: @account, status: status)
|
||||
pin&.destroy!
|
||||
end
|
||||
|
||||
def remove_featured_tags
|
||||
name = @object['name']&.delete_prefix('#')
|
||||
|
||||
return if name.blank?
|
||||
|
||||
featured_tag = FeaturedTag.by_name(name).find_by(account: @account)
|
||||
featured_tag&.destroy!
|
||||
end
|
||||
end
|
||||
|
@@ -278,7 +278,7 @@ class FeedManager
|
||||
next if last_status_score < oldest_home_score
|
||||
end
|
||||
|
||||
statuses = target_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, :media_attachments, reblog: :account).limit(limit)
|
||||
statuses = target_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, :media_attachments, :account, reblog: :account).limit(limit)
|
||||
crutches = build_crutches(account.id, statuses)
|
||||
|
||||
statuses.each do |status|
|
||||
@@ -484,7 +484,7 @@ class FeedManager
|
||||
# @param [Hash] crutches
|
||||
# @return [Boolean]
|
||||
def filter_from_tags?(status, receiver_id, crutches)
|
||||
receiver_id != status.account_id && (((crutches[:active_mentions][status.id] || []) + [status.account_id]).any? { |target_account_id| crutches[:blocking][target_account_id] || crutches[:muting][target_account_id] } || crutches[:blocked_by][status.account_id] || crutches[:domain_blocking][status.account.domain])
|
||||
receiver_id == status.account_id || ((crutches[:active_mentions][status.id] || []) + [status.account_id]).any? { |target_account_id| crutches[:blocking][target_account_id] || crutches[:muting][target_account_id] } || crutches[:blocked_by][status.account_id] || crutches[:domain_blocking][status.account.domain]
|
||||
end
|
||||
|
||||
# Adds a status to an account's feed, returning true if a status was
|
||||
@@ -605,7 +605,7 @@ class FeedManager
|
||||
crutches[:hiding_reblogs] = Follow.where(account_id: receiver_id, target_account_id: statuses.map { |s| s.account_id if s.reblog? }.compact, show_reblogs: false).pluck(:target_account_id).index_with(true)
|
||||
crutches[:blocking] = Block.where(account_id: receiver_id, target_account_id: check_for_blocks).pluck(:target_account_id).index_with(true)
|
||||
crutches[:muting] = Mute.where(account_id: receiver_id, target_account_id: check_for_blocks).pluck(:target_account_id).index_with(true)
|
||||
crutches[:domain_blocking] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.map { |s| s.reblog&.account&.domain }.compact).pluck(:domain).index_with(true)
|
||||
crutches[:domain_blocking] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.flat_map { |s| [s.account.domain, s.reblog&.account&.domain] }.compact).pluck(:domain).index_with(true)
|
||||
crutches[:blocked_by] = Block.where(target_account_id: receiver_id, account_id: statuses.map { |s| s.reblog&.account_id }.compact).pluck(:account_id).index_with(true)
|
||||
|
||||
crutches
|
||||
|
@@ -8,16 +8,14 @@ class PermalinkRedirector
|
||||
end
|
||||
|
||||
def redirect_path
|
||||
if path_segments[0] == 'web'
|
||||
if path_segments[1].present? && path_segments[1].start_with?('@') && path_segments[2] =~ /\d/
|
||||
find_status_url_by_id(path_segments[2])
|
||||
elsif path_segments[1].present? && path_segments[1].start_with?('@')
|
||||
find_account_url_by_name(path_segments[1])
|
||||
elsif path_segments[1] == 'statuses' && path_segments[2] =~ /\d/
|
||||
find_status_url_by_id(path_segments[2])
|
||||
elsif path_segments[1] == 'accounts' && path_segments[2] =~ /\d/
|
||||
find_account_url_by_id(path_segments[2])
|
||||
end
|
||||
if path_segments[0].present? && path_segments[0].start_with?('@') && path_segments[1] =~ /\d/
|
||||
find_status_url_by_id(path_segments[1])
|
||||
elsif path_segments[0].present? && path_segments[0].start_with?('@')
|
||||
find_account_url_by_name(path_segments[0])
|
||||
elsif path_segments[0] == 'statuses' && path_segments[1] =~ /\d/
|
||||
find_status_url_by_id(path_segments[1])
|
||||
elsif path_segments[0] == 'accounts' && path_segments[1] =~ /\d/
|
||||
find_account_url_by_id(path_segments[1])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,18 +27,12 @@ class PermalinkRedirector
|
||||
|
||||
def find_status_url_by_id(id)
|
||||
status = Status.find_by(id: id)
|
||||
|
||||
return unless status&.distributable?
|
||||
|
||||
ActivityPub::TagManager.instance.url_for(status)
|
||||
ActivityPub::TagManager.instance.url_for(status) if status&.distributable? && !status.account.local?
|
||||
end
|
||||
|
||||
def find_account_url_by_id(id)
|
||||
account = Account.find_by(id: id)
|
||||
|
||||
return unless account
|
||||
|
||||
ActivityPub::TagManager.instance.url_for(account)
|
||||
ActivityPub::TagManager.instance.url_for(account) if account.present? && !account.local?
|
||||
end
|
||||
|
||||
def find_account_url_by_name(name)
|
||||
@@ -48,12 +40,6 @@ class PermalinkRedirector
|
||||
domain = nil if TagManager.instance.local_domain?(domain)
|
||||
account = Account.find_remote(username, domain)
|
||||
|
||||
return unless account
|
||||
|
||||
ActivityPub::TagManager.instance.url_for(account)
|
||||
end
|
||||
|
||||
def find_tag_url_by_name(name)
|
||||
tag_path(CGI.unescape(name))
|
||||
ActivityPub::TagManager.instance.url_for(account) if account.present? && !account.local?
|
||||
end
|
||||
end
|
||||
|
@@ -17,6 +17,10 @@ class TranslationService
|
||||
end
|
||||
end
|
||||
|
||||
def self.configured?
|
||||
ENV['DEEPL_API_KEY'].present? || ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
|
||||
end
|
||||
|
||||
def translate(_text, _source_language, _target_language)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
@@ -46,7 +46,7 @@ class TranslationService::DeepL < TranslationService
|
||||
|
||||
raise UnexpectedResponseError unless json.is_a?(Hash)
|
||||
|
||||
Translation.new(text: json.dig('translations', 0, 'text'), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase)
|
||||
Translation.new(text: json.dig('translations', 0, 'text'), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase, provider: 'DeepL.com')
|
||||
rescue Oj::ParseError
|
||||
raise UnexpectedResponseError
|
||||
end
|
||||
|
@@ -37,7 +37,7 @@ class TranslationService::LibreTranslate < TranslationService
|
||||
|
||||
raise UnexpectedResponseError unless json.is_a?(Hash)
|
||||
|
||||
Translation.new(text: json['translatedText'], detected_source_language: source_language)
|
||||
Translation.new(text: json['translatedText'], detected_source_language: source_language, provider: 'LibreTranslate')
|
||||
rescue Oj::ParseError
|
||||
raise UnexpectedResponseError
|
||||
end
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TranslationService::Translation < ActiveModelSerializers::Model
|
||||
attributes :text, :detected_source_language
|
||||
attributes :text, :detected_source_language, :provider
|
||||
end
|
||||
|
@@ -8,8 +8,8 @@ class Vacuum::MediaAttachmentsVacuum
|
||||
end
|
||||
|
||||
def perform
|
||||
vacuum_cached_files! if retention_period?
|
||||
vacuum_orphaned_records!
|
||||
vacuum_cached_files! if retention_period?
|
||||
end
|
||||
|
||||
private
|
||||
|
@@ -9,7 +9,6 @@ class Vacuum::PreviewCardsVacuum
|
||||
|
||||
def perform
|
||||
vacuum_cached_images! if retention_period?
|
||||
vacuum_orphaned_records!
|
||||
end
|
||||
|
||||
private
|
||||
@@ -21,18 +20,10 @@ class Vacuum::PreviewCardsVacuum
|
||||
end
|
||||
end
|
||||
|
||||
def vacuum_orphaned_records!
|
||||
orphaned_preview_cards.in_batches.destroy_all
|
||||
end
|
||||
|
||||
def preview_cards_past_retention_period
|
||||
PreviewCard.cached.where(PreviewCard.arel_table[:updated_at].lt(@retention_period.ago))
|
||||
end
|
||||
|
||||
def orphaned_preview_cards
|
||||
PreviewCard.where('NOT EXISTS (SELECT 1 FROM preview_cards_statuses WHERE preview_cards_statuses.preview_card_id = preview_cards.id)').where(PreviewCard.arel_table[:created_at].lt(TTL.ago))
|
||||
end
|
||||
|
||||
def retention_period?
|
||||
@retention_period.present?
|
||||
end
|
||||
|
Reference in New Issue
Block a user