From 29d01f504ac575e5e4135124123f809206755174 Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 17 Dec 2024 17:10:06 -0600 Subject: [PATCH] Refactor incoming avatar/header alt text handling --- .../activitypub/process_account_service.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 280fd426155d80..1262cd0cc43d4f 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -199,15 +199,19 @@ def actor_type end end - def image_url(key) + def image(key) value = first_of_value(@json[key]) return if value.nil? if value.is_a?(String) value = fetch_resource_without_id_validation(value) - return if value.nil? + nil if value.nil? end + end + + def image_url(key) + value = image(key) value = first_of_value(value['url']) if value.is_a?(Hash) && value['type'] == 'Image' value = value['href'] if value.is_a?(Hash) @@ -215,11 +219,11 @@ def image_url(key) end def image_description(key) - value = first_of_value(@json[key]) + value = image(key) - return if value.nil? || value.is_a?(String) + return unless value.is_a?(Hash) - value = first_of_value(value['summary']) || first_of_value(value['name']) if value.is_a?(Hash) && value['type'] == 'Image' + value = first_of_value(value['summary']) || first_of_value(value['name']) if value['type'] == 'Image' value if value.is_a?(String) end