2017-10-04 00:39:32 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-05-02 12:08:48 +02:00
|
|
|
# NOTE: This is a deprecated worker, only kept to not break ongoing imports
|
|
|
|
# on upgrade. See `Import::RowWorker` for its replacement.
|
|
|
|
|
2017-10-04 00:39:32 +02:00
|
|
|
class Import::RelationshipWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
sidekiq_options queue: 'pull', retry: 8, dead: false
|
|
|
|
|
2021-05-06 14:22:54 +02:00
|
|
|
def perform(account_id, target_account_uri, relationship, options)
|
2017-10-04 00:39:32 +02:00
|
|
|
from_account = Account.find(account_id)
|
2020-06-09 10:26:58 +02:00
|
|
|
target_domain = domain(target_account_uri)
|
2024-04-02 17:47:40 +02:00
|
|
|
target_account = stoplight_wrapper(target_domain).run { ResolveAccountService.new.call(target_account_uri, { check_delivery_availability: true }) }
|
2019-04-08 07:28:27 +02:00
|
|
|
options.symbolize_keys!
|
2017-10-04 00:39:32 +02:00
|
|
|
|
|
|
|
return if target_account.nil?
|
|
|
|
|
|
|
|
case relationship
|
|
|
|
when 'follow'
|
2020-12-26 23:52:46 +01:00
|
|
|
begin
|
2021-05-06 14:22:54 +02:00
|
|
|
FollowService.new.call(from_account, target_account, **options)
|
2020-12-26 23:52:46 +01:00
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
raise if FollowLimitValidator.limit_for_account(from_account) < from_account.following_count
|
|
|
|
end
|
2019-02-03 03:59:51 +01:00
|
|
|
when 'unfollow'
|
|
|
|
UnfollowService.new.call(from_account, target_account)
|
2017-10-04 00:39:32 +02:00
|
|
|
when 'block'
|
|
|
|
BlockService.new.call(from_account, target_account)
|
2019-02-03 03:59:51 +01:00
|
|
|
when 'unblock'
|
|
|
|
UnblockService.new.call(from_account, target_account)
|
2017-10-04 00:39:32 +02:00
|
|
|
when 'mute'
|
2021-05-06 14:22:54 +02:00
|
|
|
MuteService.new.call(from_account, target_account, **options)
|
2019-02-03 03:59:51 +01:00
|
|
|
when 'unmute'
|
|
|
|
UnmuteService.new.call(from_account, target_account)
|
2017-10-04 00:39:32 +02:00
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
2020-06-09 10:26:58 +02:00
|
|
|
|
|
|
|
def domain(uri)
|
|
|
|
domain = uri.is_a?(Account) ? uri.domain : uri.split('@')[1]
|
|
|
|
TagManager.instance.local_domain?(domain) ? nil : TagManager.instance.normalize_domain(domain)
|
|
|
|
end
|
|
|
|
|
2024-04-02 17:47:40 +02:00
|
|
|
def stoplight_wrapper(domain)
|
2020-06-09 10:26:58 +02:00
|
|
|
if domain.present?
|
2024-04-02 17:47:40 +02:00
|
|
|
Stoplight("source:#{domain}")
|
2020-06-09 10:26:58 +02:00
|
|
|
.with_fallback { nil }
|
|
|
|
.with_threshold(1)
|
|
|
|
.with_cool_off_time(5.minutes.seconds)
|
|
|
|
.with_error_handler { |error, handle| error.is_a?(HTTP::Error) || error.is_a?(OpenSSL::SSL::SSLError) ? handle.call(error) : raise(error) }
|
|
|
|
else
|
2024-04-02 17:47:40 +02:00
|
|
|
Stoplight('domain-blank')
|
2020-06-09 10:26:58 +02:00
|
|
|
end
|
|
|
|
end
|
2017-10-04 00:39:32 +02:00
|
|
|
end
|