make blocking domains actually block the accounts
parent
992bd7c752
commit
29643fd6c4
|
@ -23,6 +23,7 @@ class Api::V1::DomainBlocksController < Api::BaseController
|
|||
|
||||
def destroy
|
||||
current_account.unblock_domain!(domain_block_params[:domain])
|
||||
AfterAccountDomainUnblockWorker.perform_async(current_account.id, domain_block_params[:domain])
|
||||
render_empty
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
@account = Account.find_remote(@username, @domain)
|
||||
@old_public_key = @account&.public_key
|
||||
|
||||
create_account if @account.nil?
|
||||
is_new_account = @account.nil?
|
||||
create_account if is_new_account
|
||||
update_account
|
||||
update_account_domain_blocks if is_new_account
|
||||
process_tags
|
||||
process_attachments
|
||||
else
|
||||
|
@ -105,6 +107,11 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
VerifyAccountLinksWorker.perform_async(@account.id)
|
||||
end
|
||||
|
||||
def update_account_domain_blocks
|
||||
return if @account.domain.nil? || @account.local?
|
||||
UpdateAccountDomainBlocksWorker.perform_async(@account.id)
|
||||
end
|
||||
|
||||
def actor_type
|
||||
if @json['type'].is_a?(Array)
|
||||
@json['type'].find { |type| ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(type) }
|
||||
|
|
|
@ -10,6 +10,7 @@ class AfterBlockDomainFromAccountService < BaseService
|
|||
|
||||
reject_existing_followers!
|
||||
reject_pending_follow_requests!
|
||||
block_accounts!
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -26,6 +27,12 @@ class AfterBlockDomainFromAccountService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def block_accounts!
|
||||
Account.where(domain: @domain).find_each do |blocked_account|
|
||||
BlockService.new.call(@account, blocked_account)
|
||||
end
|
||||
end
|
||||
|
||||
def reject_follow!(follow)
|
||||
follow.destroy
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AfterUnblockDomainFromAccountService < BaseService
|
||||
def call(account, domain)
|
||||
@account = account
|
||||
@domain = domain
|
||||
|
||||
unblock_accounts!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unblock_accounts!
|
||||
@account.blocking.where(domain: @domain).find_each do |blocked_account|
|
||||
UnblockService.new.call(@account, blocked_account)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UpdateAccountDomainBlocksService < BaseService
|
||||
def call(account)
|
||||
@account = account
|
||||
@domain = account.domain
|
||||
|
||||
block_where_domain_blocked!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def block_where_domain_blocked!
|
||||
account_ids = AccountDomainBlock.distinct.where(domain: @domain).pluck(:account_id)
|
||||
Account.where(id: account_ids).find_each do |blocked_by|
|
||||
BlockService.new.call(blocked_by, @account)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AfterAccountDomainUnblockWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(account_id, domain)
|
||||
AfterUnblockDomainFromAccountService.new.call(Account.find(account_id), domain)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UpdateAccountDomainBlocksWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(account_id)
|
||||
UpdateAccountDomainBlocksService.new.call(Account.find(account_id))
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue