Merge commit 'e3f0b955b8
' into kbtopic-remove-quoteMerge
This commit is contained in:
commit
29b904483e
357 changed files with 1914 additions and 1355 deletions
|
@ -57,6 +57,8 @@ class ActivityPub::Activity
|
|||
ActivityPub::Activity::Remove
|
||||
when 'Move'
|
||||
ActivityPub::Activity::Move
|
||||
when 'QuoteRequest'
|
||||
ActivityPub::Activity::QuoteRequest
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,7 +98,14 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
end
|
||||
|
||||
def process_status_params
|
||||
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url, object: @object, account: @account, friend_domain: friend_domain?)
|
||||
@status_parser = ActivityPub::Parser::StatusParser.new(
|
||||
@json,
|
||||
followers_collection: @account.followers_url,
|
||||
actor_uri: ActivityPub::TagManager.instance.uri_for(@account),
|
||||
object: @object,
|
||||
account: @account,
|
||||
friend_domain: friend_domain?
|
||||
)
|
||||
|
||||
attachment_ids = process_attachments.take(Status::MEDIA_ATTACHMENTS_LIMIT_FROM_REMOTE).map(&:id)
|
||||
|
||||
|
@ -122,6 +129,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
media_attachment_ids: attachment_ids,
|
||||
ordered_media_attachment_ids: attachment_ids,
|
||||
poll: process_poll,
|
||||
quote_approval_policy: @status_parser.quote_policy,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
30
app/lib/activitypub/activity/quote_request.rb
Normal file
30
app/lib/activitypub/activity/quote_request.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::Activity::QuoteRequest < ActivityPub::Activity
|
||||
include Payloadable
|
||||
|
||||
def perform
|
||||
return unless Mastodon::Feature.inbound_quotes_enabled?
|
||||
return if non_matching_uri_hosts?(@account.uri, @json['id'])
|
||||
|
||||
quoted_status = status_from_uri(object_uri)
|
||||
return if quoted_status.nil? || !quoted_status.account.local? || !quoted_status.distributable?
|
||||
|
||||
# For now, we don't support being quoted by external servers
|
||||
reject_quote_request!(quoted_status)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reject_quote_request!(quoted_status)
|
||||
quote = Quote.new(
|
||||
quoted_status: quoted_status,
|
||||
quoted_account: quoted_status.account,
|
||||
status: Status.new(account: @account, uri: @json['instrument']),
|
||||
account: @account,
|
||||
activity_uri: @json['id']
|
||||
)
|
||||
json = Oj.dump(serialize_payload(quote, ActivityPub::RejectQuoteRequestSerializer))
|
||||
ActivityPub::DeliveryWorker.perform_async(json, quoted_status.account_id, @account.inbox_url)
|
||||
end
|
||||
end
|
|
@ -11,6 +11,7 @@ class ActivityPub::Parser::StatusParser
|
|||
# @param [Hash] json
|
||||
# @param [Hash] options
|
||||
# @option options [String] :followers_collection
|
||||
# @option options [String] :actor_uri
|
||||
# @option options [Hash] :object
|
||||
def initialize(json, **options)
|
||||
@json = json
|
||||
|
@ -135,6 +136,18 @@ class ActivityPub::Parser::StatusParser
|
|||
@object.dig(:shares, :totalItems)
|
||||
end
|
||||
|
||||
def quote_policy
|
||||
flags = 0
|
||||
policy = @object.dig('interactionPolicy', 'canQuote')
|
||||
return flags if policy.blank?
|
||||
|
||||
flags |= quote_subpolicy(policy['automaticApproval'])
|
||||
flags <<= 16
|
||||
flags |= quote_subpolicy(policy['manualApproval'])
|
||||
|
||||
flags
|
||||
end
|
||||
|
||||
def quote_uri
|
||||
%w(quote _misskey_quote quoteUrl quoteUri).filter_map do |key|
|
||||
value_or_id(as_array(@object[key]).first)
|
||||
|
@ -147,6 +160,29 @@ class ActivityPub::Parser::StatusParser
|
|||
|
||||
private
|
||||
|
||||
def quote_subpolicy(subpolicy)
|
||||
flags = 0
|
||||
|
||||
allowed_actors = as_array(subpolicy)
|
||||
allowed_actors.uniq!
|
||||
|
||||
flags |= Status::QUOTE_APPROVAL_POLICY_FLAGS[:public] if allowed_actors.delete('as:Public') || allowed_actors.delete('Public') || allowed_actors.delete('https://www.w3.org/ns/activitystreams#Public')
|
||||
flags |= Status::QUOTE_APPROVAL_POLICY_FLAGS[:followers] if allowed_actors.delete(@options[:followers_collection])
|
||||
# TODO: we don't actually store that collection URI
|
||||
# flags |= Status::QUOTE_APPROVAL_POLICY_FLAGS[:followed]
|
||||
|
||||
# Remove the special-meaning actor URI
|
||||
allowed_actors.delete(@options[:actor_uri])
|
||||
|
||||
# Tagged users are always allowed, so remove them
|
||||
allowed_actors -= as_array(@object['tag']).filter_map { |tag| tag['href'] if equals_or_includes?(tag['type'], 'Mention') }
|
||||
|
||||
# Any unrecognized actor is marked as unknown
|
||||
flags |= Status::QUOTE_APPROVAL_POLICY_FLAGS[:unknown] unless allowed_actors.empty?
|
||||
|
||||
flags
|
||||
end
|
||||
|
||||
def raw_language_code
|
||||
if content_language_map?
|
||||
@object['contentMap'].keys.first
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue