Merge tag 'v2.7.0' into instance_only_statuses
This commit is contained in:
@ -17,7 +17,7 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
||||
uri: @json['id'],
|
||||
created_at: @json['published'],
|
||||
override_timestamps: @options[:override_timestamps],
|
||||
visibility: original_status.visibility
|
||||
visibility: visibility_from_audience
|
||||
)
|
||||
|
||||
distribute(status)
|
||||
@ -26,6 +26,18 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
||||
|
||||
private
|
||||
|
||||
def visibility_from_audience
|
||||
if equals_or_includes?(@json['to'], ActivityPub::TagManager::COLLECTIONS[:public])
|
||||
:public
|
||||
elsif equals_or_includes?(@json['cc'], ActivityPub::TagManager::COLLECTIONS[:public])
|
||||
:unlisted
|
||||
elsif equals_or_includes?(@json['to'], @account.followers_url)
|
||||
:private
|
||||
else
|
||||
:direct
|
||||
end
|
||||
end
|
||||
|
||||
def announceable?(status)
|
||||
status.account_id == @account.id || status.public_visibility? || status.unlisted_visibility?
|
||||
end
|
||||
|
@ -5,10 +5,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
CONVERTED_TYPES = %w(Image Video Article Page).freeze
|
||||
|
||||
def perform
|
||||
return if delete_arrived_first?(object_uri) || unsupported_object_type? || invalid_origin?(@object['id'])
|
||||
return if unsupported_object_type? || invalid_origin?(@object['id'])
|
||||
return if Tombstone.exists?(uri: @object['id'])
|
||||
|
||||
RedisLock.acquire(lock_options) do |lock|
|
||||
if lock.acquired?
|
||||
return if delete_arrived_first?(object_uri)
|
||||
|
||||
@status = find_existing_status
|
||||
|
||||
if @status.nil?
|
||||
@ -59,7 +62,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
account: @account,
|
||||
text: text_from_content || '',
|
||||
language: detected_language,
|
||||
spoiler_text: text_from_summary || '',
|
||||
spoiler_text: converted_object_type? ? '' : (text_from_summary || ''),
|
||||
created_at: @object['published'],
|
||||
override_timestamps: @options[:override_timestamps],
|
||||
reply: @object['inReplyTo'].present?,
|
||||
@ -254,7 +257,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
end
|
||||
|
||||
def text_from_content
|
||||
return Formatter.instance.linkify([text_from_name, object_url || @object['id']].join(' ')) if converted_object_type?
|
||||
return Formatter.instance.linkify([[text_from_name, text_from_summary.presence].compact.join("\n\n"), object_url || @object['id']].join(' ')) if converted_object_type?
|
||||
|
||||
if @object['content'].present?
|
||||
@object['content']
|
||||
|
@ -21,11 +21,14 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
||||
def delete_note
|
||||
return if object_uri.nil?
|
||||
|
||||
unless invalid_origin?(object_uri)
|
||||
RedisLock.acquire(lock_options) { |_lock| delete_later!(object_uri) }
|
||||
Tombstone.find_or_create_by(uri: object_uri, account: @account)
|
||||
end
|
||||
|
||||
@status = Status.find_by(uri: object_uri, account: @account)
|
||||
@status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
|
||||
|
||||
delete_later!(object_uri)
|
||||
|
||||
return if @status.nil?
|
||||
|
||||
if @status.public_visibility? || @status.unlisted_visibility?
|
||||
@ -68,4 +71,17 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
||||
def payload
|
||||
@payload ||= Oj.dump(@json)
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: Redis.current, key: "create:#{object_uri}" }
|
||||
end
|
||||
|
||||
def invalid_origin?(url)
|
||||
return true if unsupported_uri_scheme?(url)
|
||||
|
||||
needle = Addressable::URI.parse(url).host
|
||||
haystack = Addressable::URI.parse(@account.uri).host
|
||||
|
||||
!haystack.casecmp(needle).zero?
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user