diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/block_service.rb | 4 | ||||
-rw-r--r-- | app/services/favourite_service.rb | 4 | ||||
-rw-r--r-- | app/services/follow_service.rb | 7 | ||||
-rw-r--r-- | app/services/notify_service.rb | 5 | ||||
-rw-r--r-- | app/services/process_interaction_service.rb | 15 | ||||
-rw-r--r-- | app/services/reblog_service.rb | 4 | ||||
-rw-r--r-- | app/services/unblock_service.rb | 5 |
7 files changed, 37 insertions, 7 deletions
diff --git a/app/services/block_service.rb b/app/services/block_service.rb index 66146a72a..b08cf8ca8 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/favourite_service.rb b/app/services/favourite_service.rb index 5c04cfee4..d5fbd29e9 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -6,12 +6,14 @@ class FavouriteService < BaseService # @param [Status] status # @return [Favourite] def call(account, status) + raise Mastodon::NotPermitted unless status.permitted?(account) + favourite = Favourite.create!(account: account, status: status) Pubsubhubbub::DistributionWorker.perform_async(favourite.stream_entry.id) if status.local? - NotifyService.new.call(status.account, favourite) + NotifyService.new.call(favourite.status.account, favourite) else NotificationWorker.perform_async(favourite.stream_entry.id, status.account_id) end diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index a73ec344d..555f01b6d 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -20,7 +20,12 @@ class FollowService < BaseService private def request_follow(source_account, target_account) - FollowRequest.create!(account: source_account, target_account: target_account) + return unless target_account.local? + + follow_request = FollowRequest.create!(account: source_account, target_account: target_account) + NotifyService.new.call(target_account, follow_request) + + follow_request end def direct_follow(source_account, target_account) diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index 8263c4376..2fb1d3919 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -32,6 +32,10 @@ class NotifyService < BaseService false end + def blocked_follow_request? + false + end + def blocked? blocked = @recipient.suspended? # Skip if the recipient account is suspended anyway blocked ||= @recipient.id == @notification.from_account.id # Skip for interactions with self @@ -45,6 +49,7 @@ class NotifyService < BaseService def create_notification @notification.save! + return unless @notification.browserable? FeedManager.instance.broadcast(@recipient.id, type: 'notification', message: FeedManager.instance.inline_render(@recipient, 'api/v1/notifications/show', @notification)) end diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index 3d3cccb6a..11ec0d2dd 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -30,7 +30,7 @@ class ProcessInteractionService < BaseService case verb(xml) when :follow - follow!(account, target_account) unless target_account.locked? + follow!(account, target_account) unless target_account.locked? || target_account.blocking?(account) when :unfollow unfollow!(account, target_account) when :favorite @@ -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) diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 23b35ffd2..0cb51eecd 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -14,9 +14,9 @@ class ReblogService < BaseService Pubsubhubbub::DistributionWorker.perform_async(reblog.stream_entry.id) if reblogged_status.local? - NotifyService.new.call(reblogged_status.account, reblog) + NotifyService.new.call(reblog.reblog.account, reblog) else - NotificationWorker.perform_async(reblog.stream_entry.id, reblogged_status.account_id) + NotificationWorker.perform_async(reblog.stream_entry.id, reblog.reblog.account_id) end reblog diff --git a/app/services/unblock_service.rb b/app/services/unblock_service.rb index 3658dcd71..f389364f9 100644 --- a/app/services/unblock_service.rb +++ b/app/services/unblock_service.rb @@ -2,6 +2,9 @@ class UnblockService < BaseService def call(account, target_account) - account.unblock!(target_account) if account.blocking?(target_account) + return unless account.blocking?(target_account) + + unblock = account.unblock!(target_account) + NotificationWorker.perform_async(unblock.stream_entry.id, target_account.id) unless target_account.local? end end |