diff --git a/app/helpers/json_ld_helper.rb b/app/helpers/json_ld_helper.rb index 03809a166c..0277ae0bee 100644 --- a/app/helpers/json_ld_helper.rb +++ b/app/helpers/json_ld_helper.rb @@ -17,6 +17,22 @@ module JsonLdHelper value.is_a?(Array) ? value.first : value end + # Some attributes we read can be either `xsd:string` or `rdf:langString` + # and will lead to different compacted forms depending on which they are. + # Furthermore, we don't unconditionally compact to our context, so we + # may also find non-compacted forms. + # This is the case of `summary`, `name` and `content` as defined in ActivityStreams. + def first_lang_string(json, name) + if json[name] + value = first_of_value(json[name]) + return value if value.is_a?(String) + + value['@value'] if value.is_a?(Hash) + elsif json["#{name}Map"] + json["#{name}Map"].values.first + end + end + def uri_from_bearcap(str) if str&.start_with?('bear:') Addressable::URI.parse(str).query_values['u'] diff --git a/app/lib/activitypub/parser/media_attachment_parser.rb b/app/lib/activitypub/parser/media_attachment_parser.rb index 2212c24c45..462cfc5b53 100644 --- a/app/lib/activitypub/parser/media_attachment_parser.rb +++ b/app/lib/activitypub/parser/media_attachment_parser.rb @@ -29,7 +29,7 @@ class ActivityPub::Parser::MediaAttachmentParser end def description - str = @json['summary'].presence || @json['name'].presence + str = first_lang_string(@json, 'summary').presence || first_lang_string(@json, 'name').presence str = str.strip[0...MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT] if str.present? str end diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index e4bebabff0..d1179e5d28 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -256,7 +256,7 @@ class ActivityPub::ProcessAccountService < BaseService if value.is_a?(Hash) && value['type'] == 'Image' url = first_of_value(value['url']) url = url['href'] if url.is_a?(Hash) - description = value['summary'].presence || value['name'].presence + description = first_lang_string(value, 'summary').presence || first_lang_string(value, 'name').presence description = description.strip[0...MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT] if description.present? else url = value