From c04002b340090795f1e54645cd3a7030ffd4bc21 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 2 Jan 2017 12:17:51 +0100 Subject: [PATCH] Federate blocks with the http://mastodon.social/schema/1.0 verb namespace --- app/lib/tag_manager.rb | 2 ++ app/services/block_service.rb | 4 +++- app/services/process_interaction_service.rb | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/lib/tag_manager.rb b/app/lib/tag_manager.rb index 78dec28aa64..4af43320034 100644 --- a/app/lib/tag_manager.rb +++ b/app/lib/tag_manager.rb @@ -14,6 +14,8 @@ class TagManager delete: 'http://activitystrea.ms/schema/1.0/delete', follow: 'http://activitystrea.ms/schema/1.0/follow', unfollow: 'http://ostatus.org/schema/1.0/unfollow', + block: 'http://mastodon.social/schema/1.0/block', + unblock: 'http://mastodon.social/schema/1.0/unblock', }.freeze TYPES = { diff --git a/app/services/block_service.rb b/app/services/block_service.rb index 66146a72ab6..b08cf8ca83d 100644 --- a/app/services/block_service.rb +++ b/app/services/block_service.rb @@ -7,10 +7,12 @@ class BlockService < BaseService UnfollowService.new.call(account, target_account) if account.following?(target_account) UnfollowService.new.call(target_account, account) if target_account.following?(account) - account.block!(target_account) + block = account.block!(target_account) clear_timelines(account, target_account) clear_notifications(account, target_account) + + NotificationWorker.perform_async(block.stream_entry.id, target_account.id) unless target_account.local? end private diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index 450b0c5cc41..11ec0d2dd16 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -41,6 +41,10 @@ class ProcessInteractionService < BaseService add_post!(body, account) unless status(xml).nil? when :delete delete_post!(xml, account) + when :block + reflect_block!(account, target_account) + when :unblock + reflect_unblock!(account, target_account) end end rescue Goldfinger::Error, HTTP::Error, OStatus2::BadSalmonError @@ -74,6 +78,15 @@ class ProcessInteractionService < BaseService account.unfollow!(target_account) end + def reflect_block!(account, target_account) + UnfollowService.new.call(target_account, account) if target_account.following?(account) + account.block!(target_account) + end + + def reflect_unblock!(account, target_account) + UnblockService.new.call(account, target_account) + end + def delete_post!(xml, account) status = Status.find(xml.at_xpath('//xmlns:id', xmlns: TagManager::XMLNS).content)