diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 8d6203b99d..a38c4ecc0b 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -504,37 +504,45 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end SCAN_SEARCHABILITY_RE = /\[searchability:(public|followers|reactors|private)\]/ + SCAN_SEARCHABILITY_FEDIBIRD_RE = /searchable_by_(all_users|followers_only|reacted_users_only|nobody)/ def searchability - searchability = searchability_from_audience - - if searchability.nil? - note = @account&.note - return nil if note.blank? - - searchability_bio = note.scan(SCAN_SEARCHABILITY_RE).first - return nil unless searchability_bio - - searchability = searchability_bio[0] - return nil if searchability.nil? - - searchability = :public if searchability == 'public' - searchability = :private if searchability == 'followers' - searchability = :limited if searchability == 'private' - searchability = :direct if searchability == 'reactors' - end + searchability = searchability_from_audience || searchability_from_bio || (marked_as_misskey_searchability? ? :public : nil) + return nil if searchability.nil? visibility = visibility_from_audience_with_silence if searchability == visibility || searchability == :limited || searchability == :direct searchability - elsif [:public, :unlisted, :private].include?(searchability) && [:public, :public_unlisted, :unlisted, :login, :private].include?(visibility) + elsif [:public, :unlisted, :private].include?(searchability) && [:private].include?(visibility) :private else :direct end end + def searchability_from_bio + note = @account&.note + return nil if note.blank? + + searchability_bio = note.scan(SCAN_SEARCHABILITY_RE).first || note.scan(SCAN_SEARCHABILITY_FEDIBIRD_RE).first + return nil unless searchability_bio + + searchability = searchability_bio[0] + return nil if searchability.nil? + + searchability = :public if %w(public all_users).include?(searchability) + searchability = :private if %w(followers followers_only).include?(searchability) + searchability = :limited if %w(private reacted_users_only).include?(searchability) + searchability = :direct if %w(reactors nobody).include?(searchability) + + searchability + end + + def marked_as_misskey_searchability? + @marked_as_misskey_searchability ||= DomainBlock.detect_invalid_subscription?(@account.domain) + end + def visibility_from_audience if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) } :public diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 36998957e0..b05fa19476 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -110,6 +110,10 @@ class DomainBlock < ApplicationRecord !!rule_for(domain)&.reject_new_follow? end + def detect_invalid_subscription?(domain) + !!rule_for(domain)&.detect_invalid_subscription? + end + def reject_reports?(domain) !!rule_for(domain)&.reject_reports? end diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 61a2d2e9d1..9c2bda08fa 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -8,6 +8,8 @@ class ActivityPub::ProcessAccountService < BaseService SUBDOMAINS_RATELIMIT = 10 DISCOVERIES_PER_REQUEST = 400 + SCAN_SEARCHABILITY_RE = /\[searchability:(public|followers|reactors|private)\]/ + SCAN_SEARCHABILITY_FEDIBIRD_RE = /searchable_by_(all_users|followers_only|reacted_users_only|nobody)/ # Should be called with confirmed valid JSON # and WebFinger-resolved username and domain @@ -252,7 +254,12 @@ class ActivityPub::ProcessAccountService < BaseService end def searchability_from_audience - return :private if audience_searchable_by.nil? + if audience_searchable_by.nil? + bio = searchability_from_bio + return bio unless bio.nil? + + return marked_as_misskey_searchability? ? :public : :private + end if audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) } :public @@ -263,6 +270,28 @@ class ActivityPub::ProcessAccountService < BaseService end end + def searchability_from_bio + note = @json['summary'] || '' + return nil if note.blank? + + searchability_bio = note.scan(SCAN_SEARCHABILITY_RE).first || note.scan(SCAN_SEARCHABILITY_FEDIBIRD_RE).first + return nil unless searchability_bio + + searchability = searchability_bio[0] + return nil if searchability.nil? + + searchability = :public if %w(public all_users).include?(searchability) + searchability = :private if %w(followers followers_only).include?(searchability) + searchability = :limited if %w(private reacted_users_only).include?(searchability) + searchability = :direct if %w(reactors nobody).include?(searchability) + + searchability + end + + def marked_as_misskey_searchability? + domain_block&.detect_invalid_subscription + end + def subscribable_by return nil if @json['subscribableBy'].nil?