Browse Source

Fix missing focalPoint in ActivityPub JSON (#6609)

pull/4/head
Eugen Rochko 6 years ago
committed by GitHub
parent
commit
44829d8216
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions
  1. +9
    -0
      app/serializers/activitypub/note_serializer.rb
  2. +27
    -2
      spec/lib/activitypub/activity/create_spec.rb

+ 9
- 0
app/serializers/activitypub/note_serializer.rb View File

@ -90,6 +90,7 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
include RoutingHelper include RoutingHelper
attributes :type, :media_type, :url, :name attributes :type, :media_type, :url, :name
attribute :focal_point, if: :focal_point?
def type def type
'Document' 'Document'
@ -106,6 +107,14 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
def url def url
object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
end 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 end
class MentionSerializer < ActiveModel::Serializer class MentionSerializer < ActiveModel::Serializer

+ 27
- 2
spec/lib/activitypub/activity/create_spec.rb View File

@ -202,7 +202,7 @@ RSpec.describe ActivityPub::Activity::Create do
attachment: [ attachment: [
{ {
type: 'Document', type: 'Document',
mime_type: 'image/png',
mediaType: 'image/png',
url: 'http://example.com/attachment.png', url: 'http://example.com/attachment.png',
}, },
], ],
@ -217,6 +217,31 @@ RSpec.describe ActivityPub::Activity::Create do
end end
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 context 'with media attachments missing url' do
let(:object_json) do let(:object_json) do
{ {
@ -226,7 +251,7 @@ RSpec.describe ActivityPub::Activity::Create do
attachment: [ attachment: [
{ {
type: 'Document', type: 'Document',
mime_type: 'image/png',
mediaType: 'image/png',
}, },
], ],
} }

Loading…
Cancel
Save