mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Merge commit '0ef43a431d353a17419ea6664ed745b5dbfbf2f9' into glitch-soc/merge-upstream
This commit is contained in:
@@ -42,6 +42,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
def process_status
|
||||
@tags = []
|
||||
@mentions = []
|
||||
@tagged_objects = []
|
||||
@unresolved_mentions = []
|
||||
@silenced_account_ids = []
|
||||
@params = {}
|
||||
@@ -56,6 +57,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
ApplicationRecord.transaction do
|
||||
@status = Status.create!(@params.merge(quote: @quote))
|
||||
attach_tags(@status)
|
||||
attach_tagged_objects(@status)
|
||||
attach_mentions(@status)
|
||||
attach_counts(@status)
|
||||
end
|
||||
@@ -181,6 +183,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
end
|
||||
end
|
||||
|
||||
def attach_tagged_objects(status)
|
||||
@tagged_objects.each do |tagged_object|
|
||||
tagged_object.status = status
|
||||
tagged_object.save
|
||||
end
|
||||
end
|
||||
|
||||
def attach_mentions(status)
|
||||
@mentions.each do |mention|
|
||||
mention.status = status
|
||||
@@ -210,6 +219,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
process_mention tag
|
||||
elsif equals_or_includes?(tag['type'], 'Emoji')
|
||||
process_emoji tag
|
||||
elsif equals_or_includes?(tag['type'], 'FeaturedCollection')
|
||||
process_tagged_collection tag
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -266,6 +277,15 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
end
|
||||
end
|
||||
|
||||
def process_tagged_collection(tag)
|
||||
return if tag['id'].blank?
|
||||
|
||||
# TODO: We probably want to resolve unknown objects and push them to an `@unresolved_tagged_objects` on failure
|
||||
collection = ActivityPub::TagManager.instance.uri_to_resource(tag['id'], Collection)
|
||||
|
||||
@tagged_objects << TaggedObject.new(uri: ActivityPub::TagManager.instance.uri_for(collection), object: collection, ap_type: 'FeaturedCollection') if collection.present?
|
||||
end
|
||||
|
||||
def process_attachments
|
||||
return [] if @object['attachment'].nil?
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
|
||||
update_account
|
||||
elsif supported_object_type? || converted_object_type?
|
||||
update_status
|
||||
elsif equals_or_includes_any?(@object['type'], ['FeaturedCollection']) && Mastodon::Feature.collections_federation_enabled?
|
||||
update_collection
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,6 +43,12 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
|
||||
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
|
||||
end
|
||||
|
||||
def update_collection
|
||||
return reject_payload! if non_matching_uri_hosts?(@account.uri, object_uri)
|
||||
|
||||
ActivityPub::ProcessFeaturedCollectionService.new.call(@account, @object)
|
||||
end
|
||||
|
||||
def object_too_old?
|
||||
@object['published'].present? && @object['published'].to_datetime < OBJECT_AGE_THRESHOLD.ago
|
||||
rescue Date::Error
|
||||
|
||||
@@ -30,7 +30,7 @@ class ActivityPub::Parser::MediaAttachmentParser
|
||||
|
||||
def description
|
||||
str = @json['summary'].presence || @json['name'].presence
|
||||
str = str.strip[0...MediaAttachment::MAX_DESCRIPTION_LENGTH] if str.present?
|
||||
str = str.strip[0...MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT] if str.present?
|
||||
str
|
||||
end
|
||||
|
||||
|
||||
@@ -262,6 +262,14 @@ class ActivityPub::TagManager
|
||||
uri_to_resource(uri, Account)
|
||||
end
|
||||
|
||||
def uri_to_local_collection(uri)
|
||||
path_params = Rails.application.routes.recognize_path(uri)
|
||||
return unless path_params[:controller] == 'collections'
|
||||
|
||||
# TODO: check account, but this requires handling potentially two different schemes
|
||||
Collection.find_by(id: path_params[:id])
|
||||
end
|
||||
|
||||
def uri_to_local_conversation(uri)
|
||||
path_params = Rails.application.routes.recognize_path(uri)
|
||||
return unless path_params[:controller] == 'activitypub/contexts'
|
||||
@@ -279,6 +287,8 @@ class ActivityPub::TagManager
|
||||
uris_to_local_accounts([uri]).first
|
||||
when 'Conversation'
|
||||
uri_to_local_conversation(uri)
|
||||
when 'Collection'
|
||||
uri_to_local_collection(uri)
|
||||
else
|
||||
StatusFinder.new(uri).status
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user