diff options
author | David Yip <yipdw@member.fsf.org> | 2018-06-12 18:12:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 18:12:29 -0500 |
commit | f6bb50b6ece555af138df164680189b1ec57da4b (patch) | |
tree | 490c6054260f4a75fb0467f343124746c1935970 /app/services | |
parent | 34f1fd2a621ca869c17009487e2f10063812fbd0 (diff) | |
parent | fac6e392e9d76e3cca44ce142690a59afc0a9156 (diff) |
Merge pull request #539 from glitch-soc/merge-upstream
Merge upstream
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/after_block_domain_from_account_service.rb | 42 | ||||
-rw-r--r-- | app/services/block_domain_from_account_service.rb | 8 |
2 files changed, 42 insertions, 8 deletions
diff --git a/app/services/after_block_domain_from_account_service.rb b/app/services/after_block_domain_from_account_service.rb new file mode 100644 index 000000000..0f1a8505d --- /dev/null +++ b/app/services/after_block_domain_from_account_service.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class AfterBlockDomainFromAccountService < BaseService + # This service does not create an AccountDomainBlock record, + # it's meant to be called after such a record has been created + # synchronously, to "clean up" + def call(account, domain) + @account = account + @domain = domain + + reject_existing_followers! + reject_pending_follow_requests! + end + + private + + def reject_existing_followers! + @account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow| + reject_follow!(follow) + end + end + + def reject_pending_follow_requests! + FollowRequest.where(target_account: @account).where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow_request| + reject_follow!(follow_request) + end + end + + def reject_follow!(follow) + follow.destroy + + return unless follow.account.activitypub? + + json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new( + follow, + serializer: ActivityPub::RejectFollowSerializer, + adapter: ActivityPub::Adapter + ).as_json).sign!(@account)) + + ActivityPub::DeliveryWorker.perform_async(json, @account.id, follow.account.inbox_url) + end +end diff --git a/app/services/block_domain_from_account_service.rb b/app/services/block_domain_from_account_service.rb deleted file mode 100644 index cae7abcbd..000000000 --- a/app/services/block_domain_from_account_service.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class BlockDomainFromAccountService < BaseService - def call(account, domain) - account.block_domain!(domain) - account.passive_relationships.where(account: Account.where(domain: domain)).delete_all - end -end |