]> cat aescling's git repositories - mastodon.git/commitdiff
Add width and height to attachments in ActivityPub (#16245)
authordogelover911 <84288771+dogelover911@users.noreply.github.com>
Sun, 16 May 2021 21:09:03 +0000 (16:09 -0500)
committerGitHub <noreply@github.com>
Sun, 16 May 2021 21:09:03 +0000 (23:09 +0200)
Co-authored-by: dogelover911 <dogelover911@localhost>
app/serializers/activitypub/note_serializer.rb

index 6f9e1ca639183282d9bfb0daa5a3365da1b339f7..7c52b634dd12cb70fc0da9071ffc17e82d139da8 100644 (file)
@@ -170,6 +170,8 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
 
     attributes :type, :media_type, :url, :name, :blurhash
     attribute :focal_point, if: :focal_point?
+    attribute :width, if: :width?
+    attribute :height, if: :height?
 
     has_one :icon, serializer: ActivityPub::ImageSerializer, if: :thumbnail?
 
@@ -204,6 +206,22 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
     def thumbnail?
       object.thumbnail.present?
     end
+
+    def width?
+      object.file.meta&.dig('original', 'width').present?
+    end
+
+    def height?
+      object.file.meta&.dig('original', 'height').present?
+    end
+
+    def width
+      object.file.meta.dig('original', 'width')
+    end
+
+    def height
+      object.file.meta.dig('original', 'height')
+    end
   end
 
   class MentionSerializer < ActivityPub::Serializer