From 619fad6cf8078ea997554081febe850404bee73c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 11 Apr 2021 11:22:50 +0200 Subject: Remove spam check and dependency on nilsimsa gem (#16011) --- app/services/process_mentions_service.rb | 5 ----- app/services/remove_status_service.rb | 5 ----- 2 files changed, 10 deletions(-) (limited to 'app/services') diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb index 4c02c7865..73dbb1834 100644 --- a/app/services/process_mentions_service.rb +++ b/app/services/process_mentions_service.rb @@ -43,7 +43,6 @@ class ProcessMentionsService < BaseService end status.save! - check_for_spam(status) mentions.each { |mention| create_notification(mention) } end @@ -72,8 +71,4 @@ class ProcessMentionsService < BaseService def resolve_account_service ResolveAccountService.new end - - def check_for_spam(status) - SpamCheck.perform(status) - end end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index d6043fb5d..d642beeaa 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -41,7 +41,6 @@ class RemoveStatusService < BaseService remove_from_hashtags remove_from_public remove_from_media if @status.media_attachments.any? - remove_from_spam_check remove_media end @@ -163,10 +162,6 @@ class RemoveStatusService < BaseService @status.media_attachments.destroy_all end - def remove_from_spam_check - redis.zremrangebyscore("spam_check:#{@status.account_id}", @status.id, @status.id) - end - def lock_options { redis: Redis.current, key: "distribute:#{@status.id}" } end -- cgit From dde8739020eb201d1c9a31da116e3e771f1439b8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 16 Apr 2021 22:01:05 +0200 Subject: Fix reports of already suspended accounts being recorded (#16047) --- app/lib/activitypub/activity/flag.rb | 2 ++ app/services/report_service.rb | 2 ++ 2 files changed, 4 insertions(+) (limited to 'app/services') diff --git a/app/lib/activitypub/activity/flag.rb b/app/lib/activitypub/activity/flag.rb index 8dfc76f0a..b0443849a 100644 --- a/app/lib/activitypub/activity/flag.rb +++ b/app/lib/activitypub/activity/flag.rb @@ -10,6 +10,8 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity target_accounts.each do |target_account| target_statuses = target_statuses_by_account[target_account.id] + next if target_account.suspended? + ReportService.new.call( @account, target_account, diff --git a/app/services/report_service.rb b/app/services/report_service.rb index 9d9c7d6c9..bc0a8b464 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -10,6 +10,8 @@ class ReportService < BaseService @comment = options.delete(:comment) || '' @options = options + raise ActiveRecord::RecordNotFound if @target_account.suspended? + create_report! notify_staff! forward_to_origin! if !@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward]) -- cgit From 6d6000f61f7f611358a45efb3c557eb1e0a7e005 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 17 Apr 2021 14:55:46 +0200 Subject: Fix remote reporters not receiving suspend/unsuspend activities (#16050) --- app/lib/account_reach_finder.rb | 25 +++++++++++++++++++++++++ app/services/suspend_account_service.rb | 12 +++++++++++- app/services/unsuspend_account_service.rb | 15 +++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/lib/account_reach_finder.rb (limited to 'app/services') diff --git a/app/lib/account_reach_finder.rb b/app/lib/account_reach_finder.rb new file mode 100644 index 000000000..706ce8c1f --- /dev/null +++ b/app/lib/account_reach_finder.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AccountReachFinder + def initialize(account) + @account = account + end + + def inboxes + (followers_inboxes + reporters_inboxes + relay_inboxes).uniq + end + + private + + def followers_inboxes + @account.followers.inboxes + end + + def reporters_inboxes + Account.where(id: @account.targeted_reports.select(:account_id)).inboxes + end + + def relay_inboxes + Relay.enabled.pluck(:inbox_url) + end +end diff --git a/app/services/suspend_account_service.rb b/app/services/suspend_account_service.rb index 9f4da91d4..b8dc8d5e0 100644 --- a/app/services/suspend_account_service.rb +++ b/app/services/suspend_account_service.rb @@ -42,7 +42,13 @@ class SuspendAccountService < BaseService end def distribute_update_actor! - ActivityPub::UpdateDistributionWorker.perform_async(@account.id) if @account.local? + return unless @account.local? + + account_reach_finder = AccountReachFinder.new(@account) + + ActivityPub::DeliveryWorker.push_bulk(account_reach_finder.inboxes) do |inbox_url| + [signed_activity_json, @account.id, inbox_url] + end end def unmerge_from_home_timelines! @@ -90,4 +96,8 @@ class SuspendAccountService < BaseService end end end + + def signed_activity_json + @signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account)) + end end diff --git a/app/services/unsuspend_account_service.rb b/app/services/unsuspend_account_service.rb index ce9ee48ed..949c670aa 100644 --- a/app/services/unsuspend_account_service.rb +++ b/app/services/unsuspend_account_service.rb @@ -12,6 +12,7 @@ class UnsuspendAccountService < BaseService merge_into_home_timelines! merge_into_list_timelines! publish_media_attachments! + distribute_update_actor! end private @@ -36,6 +37,16 @@ class UnsuspendAccountService < BaseService # @account would now be nil. end + def distribute_update_actor! + return unless @account.local? + + account_reach_finder = AccountReachFinder.new(@account) + + ActivityPub::DeliveryWorker.push_bulk(account_reach_finder.inboxes) do |inbox_url| + [signed_activity_json, @account.id, inbox_url] + end + end + def merge_into_home_timelines! @account.followers_for_local_distribution.find_each do |follower| FeedManager.instance.merge_into_home(@account, follower) @@ -81,4 +92,8 @@ class UnsuspendAccountService < BaseService end end end + + def signed_activity_json + @signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account)) + end end -- cgit From ca3bc1b09f344f38164aa65d2554cf50d5c10cc0 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 17 Apr 2021 15:41:57 +0200 Subject: Refactor StatusReachFinder to handle followers and relays as well (#16051) --- app/lib/status_reach_finder.rb | 25 ++++++++++++++++++++++++- app/services/remove_status_service.rb | 34 +++++----------------------------- 2 files changed, 29 insertions(+), 30 deletions(-) (limited to 'app/services') diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb index 35b191dad..3aab3bde0 100644 --- a/app/lib/status_reach_finder.rb +++ b/app/lib/status_reach_finder.rb @@ -6,11 +6,22 @@ class StatusReachFinder end def inboxes - Account.where(id: reached_account_ids).inboxes + (reached_account_inboxes + followers_inboxes + relay_inboxes).uniq end private + def reached_account_inboxes + # When the status is a reblog, there are no interactions with it + # directly, we assume all interactions are with the original one + + if @status.reblog? + [] + else + Account.where(id: reached_account_ids).inboxes + end + end + def reached_account_ids [ replied_to_account_id, @@ -49,4 +60,16 @@ class StatusReachFinder def replies_account_ids @status.replies.pluck(:account_id) end + + def followers_inboxes + @status.account.followers.inboxes + end + + def relay_inboxes + if @status.public_visibility? + Relay.enabled.pluck(:inbox_url) + else + [] + end + end end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index d642beeaa..2c2a26641 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -27,10 +27,7 @@ class RemoveStatusService < BaseService # original object being removed implicitly removes reblogs # of it. The Delete activity of the original is forwarded # separately. - if @account.local? && !@options[:original_removed] - remove_from_remote_followers - remove_from_remote_reach - end + remove_from_remote_reach if @account.local? && !@options[:original_removed] # Since reblogs don't mention anyone, don't get reblogged, # favourited and don't contain their own media attachments @@ -82,13 +79,10 @@ class RemoveStatusService < BaseService end def remove_from_remote_reach - return if @status.reblog? - - # People who got mentioned in the status, or who - # reblogged it from someone else might not follow - # the author and wouldn't normally receive the - # delete notification - so here, we explicitly - # send it to them + # Followers, relays, people who got mentioned in the status, + # or who reblogged it from someone else might not follow + # the author and wouldn't normally receive the delete + # notification - so here, we explicitly send it to them status_reach_finder = StatusReachFinder.new(@status) @@ -97,24 +91,6 @@ class RemoveStatusService < BaseService end end - def remove_from_remote_followers - ActivityPub::DeliveryWorker.push_bulk(@account.followers.inboxes) do |inbox_url| - [signed_activity_json, @account.id, inbox_url] - end - - relay! if relayable? - end - - def relayable? - @status.public_visibility? - end - - def relay! - ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url| - [signed_activity_json, @account.id, inbox_url] - end - end - def signed_activity_json @signed_activity_json ||= Oj.dump(serialize_payload(@status, @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, signer: @account)) end -- cgit