From cbe29bcdee9947a6b833b245428f2ccf87ffedbc Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 14 Mar 2023 20:35:05 +0900 Subject: [PATCH] Add activitypub posts limit on group --- app/services/group_reblog_service.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/services/group_reblog_service.rb b/app/services/group_reblog_service.rb index c770c1ae4f..ddff566173 100644 --- a/app/services/group_reblog_service.rb +++ b/app/services/group_reblog_service.rb @@ -3,6 +3,9 @@ class GroupReblogService < BaseService include RoutingHelper + CHECK_POSTS_DOMAIN_SIZE = 30 + REQUESTED_LOCAL_POSTS = 5 + def call(status) visibility = status.visibility.to_sym return nil if !%i(public public_unlisted unlisted private direct).include?(visibility) @@ -13,10 +16,17 @@ class GroupReblogService < BaseService accounts.each do |account| next unless account.local? next if account.group_message_following_only && !account.following?(status.account) + next unless status.account.following?(account) next unless account.group? next if account.id == status.account_id next if transcription && !account.group_allow_private_message + if status.account.activitypub? + domains = account.statuses.order(created_at: 'DESC').where('reblog_of_id > 0').map(&:reblog).map(&:account).map(&:domain).take(CHECK_POSTS_DOMAIN_SIZE).to_a + local_count = domains.where { |domain| !domain }.size + next if local_count < REQUESTED_LOCAL_POSTS + end + ReblogService.new.call(account, status, { visibility: status.visibility }) if !transcription if transcription