5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 19:56:21 +00:00

fix: mostrar link externo al comentario #15638

This commit is contained in:
f 2024-03-18 11:21:13 -03:00
parent bdb5175fcd
commit 1623d618ee
No known key found for this signature in database
2 changed files with 41 additions and 2 deletions

View file

@ -43,6 +43,42 @@ class ActivityPub < ApplicationRecord
end
end
# Obtiene el campo `url` de diversas formas. Si es una String, asumir
# que es una URL, si es un Hash, asumir que es un Link, si es un
# Array de Strings, obtener la primera, si es de Hash, obtener el
# primer link con rel=canonical y mediaType=text/html
#
# De lo contrario devolver el ID.
#
# @todo Refactorizar
# @param object [Hash]
# @return [String]
def self.url_from_object(object)
raise unless object.respond_to?(:[])
url =
case object['url']
when String then object['url']
when Hash then object['href']
# Esto es un lío porque queremos saber si es un Array<Hash> o
# Array<String> o mezcla y obtener el que más nos convenga o
# adivinar uno.
when Array
links = object['url'].map.with_index do |link, i|
case link
when Hash then link
else { 'href' => link.to_s }
end
end
links.find do |link|
link['rel'] == 'canonical' && link['mediaType'] == 'text/html'
end&.[]('href') || links.first&.[]('href')
end
url || object['id']
end
aasm do
# Todavía no hay una decisión sobre el objeto
state :paused, initial: true

View file

@ -8,6 +8,8 @@
- in_reply_to = text_plain comment['inReplyTo']
- summary = text_plain comment['summary']
-# @todo Generar un desplegable con todas las opciones
- url = text_plain ActivityPub.url_from_object(comment)
.row.no-gutters
.col-1
@ -17,8 +19,9 @@
.d-flex.flex-row.align-items-center.justify-content-between
%h4.mb-0
%a{ href: text_plain(comment['attributedTo']) }= text_plain profile['preferredUsername']
%small
= render 'layouts/time', time: text_plain(comment['published'])
%a{ href: url }
%small
= render 'layouts/time', time: text_plain(comment['published'])
- if in_reply_to.present?
%dl
%dt.d-inline