diff options
author | Starfall <us@starfall.systems> | 2022-05-04 12:00:22 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-05-04 12:00:22 -0500 |
commit | e9b2e11520056d0ec822ac0862923d00c6a1289c (patch) | |
tree | 53b22a4fecda9846fc6c77cf4067c071a6287df0 /app/services | |
parent | 9ec0ecda66745c892961a917b18354f42dfc1f19 (diff) | |
parent | 58ac5ae643dc57ffd20017c54e7be523deaef156 (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/activitypub/fetch_featured_collection_service.rb | 34 | ||||
-rw-r--r-- | app/services/resolve_account_service.rb | 2 |
2 files changed, 24 insertions, 12 deletions
diff --git a/app/services/activitypub/fetch_featured_collection_service.rb b/app/services/activitypub/fetch_featured_collection_service.rb index 07a9fe039..37d05e055 100644 --- a/app/services/activitypub/fetch_featured_collection_service.rb +++ b/app/services/activitypub/fetch_featured_collection_service.rb @@ -7,19 +7,33 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService return if account.featured_collection_url.blank? || account.suspended? || account.local? @account = account - @json = fetch_resource(@account.featured_collection_url, true) + @json = fetch_resource(@account.featured_collection_url, true, local_follower) - return unless supported_context? + return unless supported_context?(@json) - case @json['type'] + process_items(collection_items(@json)) + end + + private + + def collection_items(collection) + collection = fetch_collection(collection['first']) if collection['first'].present? + return unless collection.is_a?(Hash) + + case collection['type'] when 'Collection', 'CollectionPage' - process_items @json['items'] + collection['items'] when 'OrderedCollection', 'OrderedCollectionPage' - process_items @json['orderedItems'] + collection['orderedItems'] end end - private + def fetch_collection(collection_or_uri) + return collection_or_uri if collection_or_uri.is_a?(Hash) + return if invalid_origin?(collection_or_uri) + + fetch_resource_without_id_validation(collection_or_uri, local_follower, true) + end def process_items(items) status_ids = items.filter_map do |item| @@ -53,11 +67,9 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService end end - def supported_context? - super(@json) - end - def local_follower - @local_follower ||= @account.followers.local.without_suspended.first + return @local_follower if defined?(@local_follower) + + @local_follower = @account.followers.local.without_suspended.first end end diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb index 21332a03e..387e2e09b 100644 --- a/app/services/resolve_account_service.rb +++ b/app/services/resolve_account_service.rb @@ -66,7 +66,7 @@ class ResolveAccountService < BaseService @username = @account.username @domain = @account.domain else - @username, @domain = uri.split('@') + @username, @domain = uri.strip.gsub(/\A@/, '').split('@') end @domain = begin |