From 9ed5eebd7ce8381af77dd2918678202a0776af4a Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 29 Mar 2018 00:52:24 +0200 Subject: Do not ignore unknown media attachments, only skip them (#6948) That way, they are displayed in a list below the corresponding toot. --- app/lib/activitypub/activity/create.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/lib/activitypub/activity/create.rb') diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 676e885c0..afee8a268 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -113,13 +113,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity media_attachments = [] as_array(@object['attachment']).each do |attachment| - next if unsupported_media_type?(attachment['mediaType']) || attachment['url'].blank? + next if attachment['url'].blank? href = Addressable::URI.parse(attachment['url']).normalize.to_s media_attachment = MediaAttachment.create(account: @account, remote_url: href, description: attachment['name'].presence, focus: attachment['focalPoint']) media_attachments << media_attachment - next if skip_download? + next if unsupported_media_type?(attachment['mediaType']) || skip_download? media_attachment.file_remote_url = href media_attachment.save -- cgit From e573bb0990ece4b1a521ccf8a4c7bec5972d3538 Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 30 Mar 2018 15:44:54 +0200 Subject: Fix compatibility with PeerTube (#6968) * Support fetching objects of convertible types by URL (fixes #6924) * Ignore invalid hashtags --- app/lib/activitypub/activity/create.rb | 2 ++ app/services/fetch_atom_service.rb | 6 +++++- app/services/resolve_url_service.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'app/lib/activitypub/activity/create.rb') diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index afee8a268..45c0e91cb 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -79,6 +79,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity hashtag = Tag.where(name: hashtag).first_or_initialize(name: hashtag) status.tags << hashtag + rescue ActiveRecord::RecordInvalid + nil end def process_mention(tag, status) diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb index 62dea8298..87076cc07 100644 --- a/app/services/fetch_atom_service.rb +++ b/app/services/fetch_atom_service.rb @@ -44,7 +44,7 @@ class FetchAtomService < BaseService json = body_to_json(body) if supported_context?(json) && json['type'] == 'Person' && json['inbox'].present? [json['id'], { prefetched_body: body, id: true }, :activitypub] - elsif supported_context?(json) && json['type'] == 'Note' + elsif supported_context?(json) && expected_type?(json) [json['id'], { prefetched_body: body, id: true }, :activitypub] else @unsupported_activity = true @@ -61,6 +61,10 @@ class FetchAtomService < BaseService end end + def expected_type?(json) + (ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES).include? json['type'] + end + def process_html(response) page = Nokogiri::HTML(response.body_with_limit) diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb index 1f2b24524..9499dc286 100644 --- a/app/services/resolve_url_service.rb +++ b/app/services/resolve_url_service.rb @@ -19,7 +19,7 @@ class ResolveURLService < BaseService case type when 'Person' FetchRemoteAccountService.new.call(atom_url, body, protocol) - when 'Note' + when 'Note', 'Article', 'Image', 'Video' FetchRemoteStatusService.new.call(atom_url, body, protocol) end end -- cgit