include RoutingHelper
attributes :type, :media_type, :url, :name
+ attribute :focal_point, if: :focal_point?
def type
'Document'
def url
object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
end
+
+ def focal_point?
+ object.file.meta.is_a?(Hash) && object.file.meta['focus'].is_a?(Hash)
+ end
+
+ def focal_point
+ [object.file.meta['focus']['x'], object.file.meta['focus']['y']]
+ end
end
class MentionSerializer < ActiveModel::Serializer
attachment: [
{
type: 'Document',
- mime_type: 'image/png',
+ mediaType: 'image/png',
url: 'http://example.com/attachment.png',
},
],
end
end
+ context 'with media attachments with focal points' do
+ let(:object_json) do
+ {
+ id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+ type: 'Note',
+ content: 'Lorem ipsum',
+ attachment: [
+ {
+ type: 'Document',
+ mediaType: 'image/png',
+ url: 'http://example.com/attachment.png',
+ focalPoint: [0.5, -0.7],
+ },
+ ],
+ }
+ end
+
+ it 'creates status' do
+ status = sender.statuses.first
+
+ expect(status).to_not be_nil
+ expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
+ end
+ end
+
context 'with media attachments missing url' do
let(:object_json) do
{
attachment: [
{
type: 'Document',
- mime_type: 'image/png',
+ mediaType: 'image/png',
},
],
}