Fix avatar and profile header descriptions not being serialized over ActivityPub (#39352)
This commit is contained in:
parent
b48f907b20
commit
e697d44144
@ -44,6 +44,16 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
end
|
||||
end
|
||||
|
||||
class ImageWithDescription < SimpleDelegator
|
||||
attr_reader :description
|
||||
|
||||
def initialize(object, description)
|
||||
super(object)
|
||||
|
||||
@description = description
|
||||
end
|
||||
end
|
||||
|
||||
has_one :endpoints, serializer: EndpointsSerializer
|
||||
|
||||
has_one :icon, serializer: ActivityPub::ImageSerializer, if: :avatar_exists?
|
||||
@ -120,11 +130,11 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
end
|
||||
|
||||
def icon
|
||||
object.avatar
|
||||
ImageWithDescription.new(object.avatar, object.avatar_description)
|
||||
end
|
||||
|
||||
def image
|
||||
object.header
|
||||
ImageWithDescription.new(object.header, object.header_description)
|
||||
end
|
||||
|
||||
def public_key
|
||||
|
||||
@ -7,6 +7,7 @@ class ActivityPub::ImageSerializer < ActivityPub::Serializer
|
||||
|
||||
attributes :type, :media_type, :url
|
||||
attribute :focal_point, if: :focal_point?
|
||||
attribute :summary, if: :summary?
|
||||
|
||||
def type
|
||||
'Image'
|
||||
@ -27,4 +28,12 @@ class ActivityPub::ImageSerializer < ActivityPub::Serializer
|
||||
def focal_point
|
||||
[object.meta['focus']['x'], object.meta['focus']['y']]
|
||||
end
|
||||
|
||||
def summary?
|
||||
object.respond_to?(:description) && object.description.present?
|
||||
end
|
||||
|
||||
def summary
|
||||
object.description
|
||||
end
|
||||
end
|
||||
|
||||
@ -74,4 +74,14 @@ RSpec.describe ActivityPub::ActorSerializer do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'avatar description' do
|
||||
let(:record) { Fabricate(:account, avatar: attachment_fixture('avatar.gif'), avatar_description: 'test') }
|
||||
|
||||
it 'includes an `icon` with the appropraite `summary`' do
|
||||
expect(subject).to include('icon' => a_hash_including(
|
||||
'summary' => 'test'
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user