diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-03-04 07:21:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-04 07:21:41 +0100 |
commit | 44829d8216001e3d8183dbd12cacc5a2f4826751 (patch) | |
tree | dd6e39363fb82e9c1fe686cb4e870a10efe43fc0 | |
parent | 49092945ab86725180e202945ae1bec03a32a634 (diff) |
Fix missing focalPoint in ActivityPub JSON (#6609)
-rw-r--r-- | app/serializers/activitypub/note_serializer.rb | 9 | ||||
-rw-r--r-- | spec/lib/activitypub/activity/create_spec.rb | 29 |
2 files changed, 36 insertions, 2 deletions
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index 24c39f3c9..d0e6290c1 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -90,6 +90,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer include RoutingHelper attributes :type, :media_type, :url, :name + attribute :focal_point, if: :focal_point? def type 'Document' @@ -106,6 +107,14 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer 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 diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 51f54a398..62b9db8c2 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -202,7 +202,7 @@ RSpec.describe ActivityPub::Activity::Create do attachment: [ { type: 'Document', - mime_type: 'image/png', + mediaType: 'image/png', url: 'http://example.com/attachment.png', }, ], @@ -217,6 +217,31 @@ RSpec.describe ActivityPub::Activity::Create do 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 { @@ -226,7 +251,7 @@ RSpec.describe ActivityPub::Activity::Create do attachment: [ { type: 'Document', - mime_type: 'image/png', + mediaType: 'image/png', }, ], } |