Actually fix incoming attachments.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 12:03:40 +0000 (13:03 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 12:06:51 +0000 (13:06 +0100)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/fixtures/mastodon-note-object.json
test/web/activity_pub/activity_pub_test.exs

index 62e43526ec55f0fc30a6a5b9ed8e364d98815d01..af6b5befce6bca012db51f1aff80ce65483d112f 100644 (file)
@@ -17,9 +17,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   end
 
   def fix_attachments(object) do
-    attachments = object["attachment"] || []
+    attachments = (object["attachment"] || [])
     |> Enum.map(fn (data) ->
-      url = [%{"type" => "Link", "mediaType" => data["mediaType"], "url" => data["url"]}]
+      url = [%{"type" => "Link", "mediaType" => data["mediaType"], "href" => data["url"]}]
       Map.put(data, "url", url)
     end)
 
index 2121e125459051ac09355d57cfe268a771e68ae1..75bed9625020a433d517c6b80c8673e4eb55fc58 100644 (file)
@@ -1 +1,9 @@
-{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"http://mastodon.example.org/users/admin/statuses/99541947525187367","type":"Note","summary":null,"content":"\u003cp\u003eyeah.\u003c/p\u003e","inReplyTo":null,"published":"2018-02-17T17:46:20Z","url":"http://mastodon.example.org/@admin/99541947525187367","attributedTo":"http://mastodon.example.org/users/admin","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["http://mastodon.example.org/users/admin/followers"],"sensitive":false,"atomUri":"http://mastodon.example.org/users/admin/statuses/99541947525187367","inReplyToAtomUri":null,"conversation":"tag:mastodon.example.org,2018-02-17:objectId=59:objectType=Conversation","attachment":[],"tag":[]}
\ No newline at end of file
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"http://mastodon.example.org/users/admin/statuses/99541947525187367","type":"Note","summary":null,"content":"\u003cp\u003eyeah.\u003c/p\u003e","inReplyTo":null,"published":"2018-02-17T17:46:20Z","url":"http://mastodon.example.org/@admin/99541947525187367","attributedTo":"http://mastodon.example.org/users/admin","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["http://mastodon.example.org/users/admin/followers"],"sensitive":false,"atomUri":"http://mastodon.example.org/users/admin/statuses/99541947525187367","inReplyToAtomUri":null,"conversation":"tag:mastodon.example.org,2018-02-17:objectId=59:objectType=Conversation","tag":[],
+    "attachment": [
+      {
+        "url": "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
+        "type": "Document",
+        "name": null,
+        "mediaType": "image/jpeg"
+      }
+    ]}
index 1debdddd4b880bc744db9b2bd257e55cced0a5d8..2ed280aa627d01c4e5ebca2c78f495279fc09cb0 100644 (file)
@@ -271,6 +271,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       assert Activity.get_create_activity_by_object_ap_id(object.data["id"])
       {:ok, object_again} = ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
 
+      assert [attachment] = object.data["attachment"]
+      assert is_list(attachment["url"])
+
       assert object == object_again
     end
   end