Fallback to Create audience when object has no defined audience (#12249)

Fixes #11137
th-downstream
ThibG 5 years ago committed by Eugen Rochko
parent 4b0a6d79dd
commit 319875ab04

@ -25,6 +25,14 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
private private
def audience_to
@object['to'] || @json['to']
end
def audience_cc
@object['cc'] || @json['cc']
end
def process_status def process_status
@tags = [] @tags = []
@mentions = [] @mentions = []
@ -75,7 +83,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end end
def process_audience def process_audience
(as_array(@object['to']) + as_array(@object['cc'])).uniq.each do |audience| (as_array(audience_to) + as_array(audience_cc)).uniq.each do |audience|
next if audience == ActivityPub::TagManager::COLLECTIONS[:public] next if audience == ActivityPub::TagManager::COLLECTIONS[:public]
# Unlike with tags, there is no point in resolving accounts we don't already # Unlike with tags, there is no point in resolving accounts we don't already
@ -291,11 +299,11 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end end
def visibility_from_audience def visibility_from_audience
if equals_or_includes?(@object['to'], ActivityPub::TagManager::COLLECTIONS[:public]) if equals_or_includes?(audience_to, ActivityPub::TagManager::COLLECTIONS[:public])
:public :public
elsif equals_or_includes?(@object['cc'], ActivityPub::TagManager::COLLECTIONS[:public]) elsif equals_or_includes?(audience_cc, ActivityPub::TagManager::COLLECTIONS[:public])
:unlisted :unlisted
elsif equals_or_includes?(@object['to'], @account.followers_url) elsif equals_or_includes?(audience_to, @account.followers_url)
:private :private
else else
:direct :direct
@ -304,7 +312,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def audience_includes?(account) def audience_includes?(account)
uri = ActivityPub::TagManager.instance.uri_for(account) uri = ActivityPub::TagManager.instance.uri_for(account)
equals_or_includes?(@object['to'], uri) || equals_or_includes?(@object['cc'], uri) equals_or_includes?(audience_to, uri) || equals_or_includes?(audience_cc, uri)
end end
def replied_to_status def replied_to_status
@ -415,7 +423,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def addresses_local_accounts? def addresses_local_accounts?
return true if @options[:delivered_to_account_id] return true if @options[:delivered_to_account_id]
local_usernames = (as_array(@object['to']) + as_array(@object['cc'])).uniq.select { |uri| ActivityPub::TagManager.instance.local_uri?(uri) }.map { |uri| ActivityPub::TagManager.instance.uri_to_local_id(uri, :username) } local_usernames = (as_array(audience_to) + as_array(audience_cc)).uniq.select { |uri| ActivityPub::TagManager.instance.local_uri?(uri) }.map { |uri| ActivityPub::TagManager.instance.uri_to_local_id(uri, :username) }
return false if local_usernames.empty? return false if local_usernames.empty?

Loading…
Cancel
Save