Also fetch atom links.
authorRoger Braun <roger@rogerbraun.net>
Fri, 4 Aug 2017 14:57:38 +0000 (16:57 +0200)
committerRoger Braun <roger@rogerbraun.net>
Fri, 4 Aug 2017 14:57:38 +0000 (16:57 +0200)
lib/pleroma/web/ostatus/handlers/note_handler.ex
lib/pleroma/web/ostatus/ostatus.ex
test/fixtures/httpoison_mock/sakamoto.atom [new file with mode: 0644]
test/fixtures/httpoison_mock/sakamoto_eal_feed.atom [new file with mode: 0644]
test/support/httpoison_mock.ex
test/web/ostatus/ostatus_test.exs

index e55f972b21bc89d25046acf76658b9a346d9bfe9..e67f67b37c03bd754a4172bf430fbe7c2c75a0e3 100644 (file)
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
     if inReplyTo && !Object.get_cached_by_ap_id(inReplyTo) do
       inReplyToHref = XML.string_from_xpath("//thr:in-reply-to[1]/@href", entry)
       if inReplyToHref do
-        OStatus.fetch_activity_from_html_url(inReplyToHref)
+        OStatus.fetch_activity_from_url(inReplyToHref)
       else
         Logger.debug("Couldn't find a href link to #{inReplyTo}")
       end
index 469d4031c3a766d290bd891024c470cea4b0a869..02a0996b0c80f6fe4bb143267af30bedb4b9a028 100644 (file)
@@ -24,45 +24,48 @@ defmodule Pleroma.Web.OStatus do
   end
 
   def handle_incoming(xml_string) do
-    doc = parse_document(xml_string)
-    entries = :xmerl_xpath.string('//entry', doc)
-
-    activities = Enum.map(entries, fn (entry) ->
-      {:xmlObj, :string, object_type} = :xmerl_xpath.string('string(/entry/activity:object-type[1])', entry)
-      {:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
-      Logger.debug("Handling #{verb}")
-
-      try do
-        case verb do
-          'http://activitystrea.ms/schema/1.0/delete' ->
-            with {:ok, activity} <- DeleteHandler.handle_delete(entry, doc), do: activity
-          'http://activitystrea.ms/schema/1.0/follow' ->
-            with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
-          'http://activitystrea.ms/schema/1.0/share' ->
-            with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
-          'http://activitystrea.ms/schema/1.0/favorite' ->
-            with {:ok, activity, favorited_activity} <- handle_favorite(entry, doc), do: [activity, favorited_activity]
-          _ ->
-            case object_type do
-              'http://activitystrea.ms/schema/1.0/note' ->
-                with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
-              'http://activitystrea.ms/schema/1.0/comment' ->
-                with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
-              _ ->
-                Logger.error("Couldn't parse incoming document")
-                nil
-            end
-        end
-      rescue
-        e ->
-          Logger.error("Error occured while handling activity")
+    with doc when doc != :error <- parse_document(xml_string) do
+      entries = :xmerl_xpath.string('//entry', doc)
+
+      activities = Enum.map(entries, fn (entry) ->
+        {:xmlObj, :string, object_type} = :xmerl_xpath.string('string(/entry/activity:object-type[1])', entry)
+        {:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
+        Logger.debug("Handling #{verb}")
+
+        try do
+          case verb do
+            'http://activitystrea.ms/schema/1.0/delete' ->
+              with {:ok, activity} <- DeleteHandler.handle_delete(entry, doc), do: activity
+            'http://activitystrea.ms/schema/1.0/follow' ->
+              with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
+            'http://activitystrea.ms/schema/1.0/share' ->
+              with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
+            'http://activitystrea.ms/schema/1.0/favorite' ->
+              with {:ok, activity, favorited_activity} <- handle_favorite(entry, doc), do: [activity, favorited_activity]
+            _ ->
+              case object_type do
+                'http://activitystrea.ms/schema/1.0/note' ->
+                  with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
+                'http://activitystrea.ms/schema/1.0/comment' ->
+                  with {:ok, activity} <- NoteHandler.handle_note(entry, doc), do: activity
+                _ ->
+                  Logger.error("Couldn't parse incoming document")
+                  nil
+              end
+          end
+        rescue
+          e ->
+            Logger.error("Error occured while handling activity")
           Logger.error(inspect(e))
           nil
-      end
-    end)
-    |> Enum.filter(&(&1))
+        end
+      end)
+      |> Enum.filter(&(&1))
 
-    {:ok, activities}
+      {:ok, activities}
+    else
+      _e -> {:error, []}
+    end
   end
 
   def make_share(entry, doc, retweeted_activity) do
@@ -111,7 +114,7 @@ defmodule Pleroma.Web.OStatus do
     else e ->
         Logger.debug("Couldn't get, will try to fetch")
         with href when not is_nil(href) <- string_from_xpath("//activity:object[1]/link[@type=\"text/html\"]/@href", entry),
-             {:ok, [favorited_activity]} <- fetch_activity_from_html_url(href) do
+             {:ok, [favorited_activity]} <- fetch_activity_from_url(href) do
           {:ok, favorited_activity}
         else e -> Logger.debug("Couldn't find href: #{inspect(e)}")
         end
@@ -278,14 +281,30 @@ defmodule Pleroma.Web.OStatus do
     end
   end
 
+  def fetch_activity_from_atom_url(url) do
+    with {:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(url, [Accept: "application/atom+xml"], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do
+      Logger.debug("Got document from #{url}, handling...")
+      handle_incoming(body)
+    else e -> Logger.debug("Couldn't get #{url}: #{inspect(e)}")
+    end
+  end
+
   def fetch_activity_from_html_url(url) do
     Logger.debug("Trying to fetch #{url}")
     with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
-         {:ok, atom_url} <- get_atom_url(body),
-         {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do
-      Logger.debug("Got document from #{url}, handling...")
-      handle_incoming(body)
+         {:ok, atom_url} <- get_atom_url(body) do
+        fetch_activity_from_atom_url(atom_url)
     else e -> Logger.debug("Couldn't get #{url}: #{inspect(e)}")
     end
   end
+
+  def fetch_activity_from_url(url) do
+    with {:ok, activities} <- fetch_activity_from_atom_url(url) do
+      {:ok, activities}
+    else
+      _e -> with {:ok, activities} <- fetch_activity_from_html_url(url) do
+              {:ok, activities}
+            end
+    end
+  end
 end
diff --git a/test/fixtures/httpoison_mock/sakamoto.atom b/test/fixtures/httpoison_mock/sakamoto.atom
new file mode 100644 (file)
index 0000000..6489467
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0"><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb><id>https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056</id><title>New note by eal</title><content type="html">&lt;a href='https://shitposter.club/user/5381'&gt;@shpuld&lt;/a&gt; &lt;a href='https://pleroma.hjkos.com/users/hj'&gt;@hj&lt;/a&gt; IM NOT GAY DAD</content><published>2017-08-04T12:51:26.130592Z</published><updated>2017-08-04T12:51:26.130592Z</updated><ostatus:conversation>https://pleroma.hjkos.com/contexts/53093c74-2100-4bf4-aac6-66d1973d03ef</ostatus:conversation><link ref="https://pleroma.hjkos.com/contexts/53093c74-2100-4bf4-aac6-66d1973d03ef" rel="ostatus:conversation"/><link type="application/atom+xml" href="https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056" rel="self"/><link type="text/html" href="https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056" rel="alternate"/><thr:in-reply-to ref="tag:shitposter.club,2017-08-04:noticeId=4027863:objectType=comment" href="https://shitposter.club/notice/4027863"/><author><id>https://social.sakamoto.gq/users/eal</id><activity:object>http://activitystrea.ms/schema/1.0/person</activity:object><uri>https://social.sakamoto.gq/users/eal</uri><poco:preferredUsername>eal</poco:preferredUsername><poco:displayName>坂本</poco:displayName><poco:note>(・ヮ・)</poco:note><name>eal</name><link rel="avatar" href="https://social.sakamoto.gq/media/7646c027-3614-4ee1-93f9-eea8f244a0d7/1A2EFE3153B9C9C3826DB511D043A26597C9F7178C8A4899FBBF808972D1659F.png"/></author><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://shitposter.club/user/5381"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://pleroma.hjkos.com/users/hj"/></entry>
\ No newline at end of file
diff --git a/test/fixtures/httpoison_mock/sakamoto_eal_feed.atom b/test/fixtures/httpoison_mock/sakamoto_eal_feed.atom
new file mode 100644 (file)
index 0000000..9340d90
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0"><id>https://social.sakamoto.gq/users/eal/feed.atom</id><title>eal's timeline</title><updated>2017-08-04T14:19:12.683854</updated><link rel="hub" href="https://social.sakamoto.gq/push/hub/eal"/><link rel="salmon" href="https://social.sakamoto.gq/users/eal/salmon"/><link rel="self" href="https://social.sakamoto.gq/users/eal/feed.atom" type="application/atom+xml"/><author><id>https://social.sakamoto.gq/users/eal</id><activity:object>http://activitystrea.ms/schema/1.0/person</activity:object><uri>https://social.sakamoto.gq/users/eal</uri><poco:preferredUsername>eal</poco:preferredUsername><poco:displayName>坂本</poco:displayName><poco:note>(・ヮ・)</poco:note><name>eal</name><link rel="avatar" href="https://social.sakamoto.gq/media/7646c027-3614-4ee1-93f9-eea8f244a0d7/1A2EFE3153B9C9C3826DB511D043A26597C9F7178C8A4899FBBF808972D1659F.png"/></author><entry><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb><id>https://social.sakamoto.gq/objects/b79a1721-23f3-45a5-9610-adb08c2afae5</id><title>New note by eal</title><content type="html">Honestly, I like all smileys that are not emoji.</content><published>2017-08-04T14:19:12.675999Z</published><updated>2017-08-04T14:19:12.675999Z</updated><ostatus:conversation>https://social.sakamoto.gq/contexts/e05ede92-8db9-4963-8b8e-e71a5797d68f</ostatus:conversation><link ref="https://social.sakamoto.gq/contexts/e05ede92-8db9-4963-8b8e-e71a5797d68f" rel="ostatus:conversation"/><link type="application/atom+xml" href="https://social.sakamoto.gq/objects/b79a1721-23f3-45a5-9610-adb08c2afae5" rel="self"/><link type="text/html" href="https://social.sakamoto.gq/objects/b79a1721-23f3-45a5-9610-adb08c2afae5" rel="alternate"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb><id>https://social.sakamoto.gq/objects/45475bf3-2dfc-4d9e-8eae-1f4f86f48982</id><title>New note by eal</title><content type="html">Then again, I like all smileys/emoticons that are not emoji.&lt;br&gt;</content><published>2017-08-04T14:19:10.113373Z</published><updated>2017-08-04T14:19:10.113373Z</updated><ostatus:conversation>https://social.sakamoto.gq/contexts/852d1605-4dcb-4ba7-9ba4-dfc37ed62fbc</ostatus:conversation><link ref="https://social.sakamoto.gq/contexts/852d1605-4dcb-4ba7-9ba4-dfc37ed62fbc" rel="ostatus:conversation"/><link type="application/atom+xml" href="https://social.sakamoto.gq/objects/45475bf3-2dfc-4d9e-8eae-1f4f86f48982" rel="self"/><link type="text/html" href="https://social.sakamoto.gq/objects/45475bf3-2dfc-4d9e-8eae-1f4f86f48982" rel="alternate"/><thr:in-reply-to ref="https://social.sakamoto.gq/objects/8f8fd6d6-cc63-40c6-a5d0-1c0e4f919368" href="https://social.sakamoto.gq/objects/8f8fd6d6-cc63-40c6-a5d0-1c0e4f919368"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://social.sakamoto.gq/users/eal"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb><id>https://social.sakamoto.gq/objects/8f8fd6d6-cc63-40c6-a5d0-1c0e4f919368</id><title>New note by eal</title><content type="html">I love the russian-style smiley.</content><published>2017-08-04T14:18:30.478552Z</published><updated>2017-08-04T14:18:30.478552Z</updated><ostatus:conversation>https://social.sakamoto.gq/contexts/852d1605-4dcb-4ba7-9ba4-dfc37ed62fbc</ostatus:conversation><link ref="https://social.sakamoto.gq/contexts/852d1605-4dcb-4ba7-9ba4-dfc37ed62fbc" rel="ostatus:conversation"/><link type="application/atom+xml" href="https://social.sakamoto.gq/objects/8f8fd6d6-cc63-40c6-a5d0-1c0e4f919368" rel="self"/><link type="text/html" href="https://social.sakamoto.gq/objects/8f8fd6d6-cc63-40c6-a5d0-1c0e4f919368" rel="alternate"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/6e69df95-f2ad-4b8e-af4a-e93ff93d64e1</id><title>eal started following https://cybre.space/users/0x3F</title><content type="html">eal started following https://cybre.space/users/0x3F</content><published>2017-08-04T14:17:24.942193Z</published><updated>2017-08-04T14:17:24.942193Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://cybre.space/users/0x3F</id><uri>https://cybre.space/users/0x3F</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/6e69df95-f2ad-4b8e-af4a-e93ff93d64e1"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://cybre.space/users/0x3F"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/54c5e260-0185-4267-a2a6-f5dd9c76c2c9</id><title>eal started following https://niu.moe/users/rye</title><content type="html">eal started following https://niu.moe/users/rye</content><published>2017-08-04T14:16:35.604739Z</published><updated>2017-08-04T14:16:35.604739Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://niu.moe/users/rye</id><uri>https://niu.moe/users/rye</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/54c5e260-0185-4267-a2a6-f5dd9c76c2c9"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://niu.moe/users/rye"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/092ca863-19a8-416c-85d7-d3f23b3c0203</id><title>eal started following https://mastodon.xyz/users/rafudesu</title><content type="html">eal started following https://mastodon.xyz/users/rafudesu</content><published>2017-08-04T14:16:10.993429Z</published><updated>2017-08-04T14:16:10.993429Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://mastodon.xyz/users/rafudesu</id><uri>https://mastodon.xyz/users/rafudesu</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/092ca863-19a8-416c-85d7-d3f23b3c0203"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mastodon.xyz/users/rafudesu"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/be5cf702-b127-423b-a6be-5f78f01a4289</id><title>eal started following https://gs.kawa-kun.com/user/2</title><content type="html">eal started following https://gs.kawa-kun.com/user/2</content><published>2017-08-04T14:15:41.804611Z</published><updated>2017-08-04T14:15:41.804611Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://gs.kawa-kun.com/user/2</id><uri>https://gs.kawa-kun.com/user/2</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/be5cf702-b127-423b-a6be-5f78f01a4289"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://gs.kawa-kun.com/user/2"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/4951e2a1-9bae-4e87-8e98-e6d2f8a52338</id><title>eal started following https://gs.kawa-kun.com/user/4885</title><content type="html">eal started following https://gs.kawa-kun.com/user/4885</content><published>2017-08-04T14:15:00.135352Z</published><updated>2017-08-04T14:15:00.135352Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://gs.kawa-kun.com/user/4885</id><uri>https://gs.kawa-kun.com/user/4885</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/4951e2a1-9bae-4e87-8e98-e6d2f8a52338"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://gs.kawa-kun.com/user/4885"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/cadf8745-b9ee-4f6c-af32-bfddb70e4607</id><title>eal started following https://mastodon.social/users/Murassa</title><content type="html">eal started following https://mastodon.social/users/Murassa</content><published>2017-08-04T14:14:36.339560Z</published><updated>2017-08-04T14:14:36.339560Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://mastodon.social/users/Murassa</id><uri>https://mastodon.social/users/Murassa</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/cadf8745-b9ee-4f6c-af32-bfddb70e4607"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mastodon.social/users/Murassa"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/a52c9aab-f0e6-4ccb-8dd3-9f417e72a41c</id><title>eal started following https://mastodon.social/users/rysiek</title><content type="html">eal started following https://mastodon.social/users/rysiek</content><published>2017-08-04T14:13:04.061572Z</published><updated>2017-08-04T14:13:04.061572Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://mastodon.social/users/rysiek</id><uri>https://mastodon.social/users/rysiek</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/a52c9aab-f0e6-4ccb-8dd3-9f417e72a41c"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mastodon.social/users/rysiek"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/738bc887-4cca-4b36-8c86-2b54d4c54732</id><title>eal started following https://mastodon.hasameli.com/users/munin</title><content type="html">eal started following https://mastodon.hasameli.com/users/munin</content><published>2017-08-04T14:12:10.514155Z</published><updated>2017-08-04T14:12:10.514155Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://mastodon.hasameli.com/users/munin</id><uri>https://mastodon.hasameli.com/users/munin</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/738bc887-4cca-4b36-8c86-2b54d4c54732"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mastodon.hasameli.com/users/munin"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/dc66ad5a-b776-4180-a8aa-e4c1bf7cb703</id><title>eal started following https://cybre.space/users/nightpool</title><content type="html">eal started following https://cybre.space/users/nightpool</content><published>2017-08-04T14:11:16.046148Z</published><updated>2017-08-04T14:11:16.046148Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://cybre.space/users/nightpool</id><uri>https://cybre.space/users/nightpool</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/dc66ad5a-b776-4180-a8aa-e4c1bf7cb703"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://cybre.space/users/nightpool"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb><id>https://social.sakamoto.gq/objects/9c5c00d7-3ce4-4c11-b965-dc5c2bda86c5</id><title>New note by eal</title><content type="html">&lt;a href='https://mastodon.zombocloud.com/users/staticsafe'&gt;@staticsafe&lt;/a&gt; privet )))</content><published>2017-08-04T14:10:08.812247Z</published><updated>2017-08-04T14:10:08.812247Z</updated><ostatus:conversation>https://social.sakamoto.gq/contexts/12a33823-0327-4c1c-a591-850ea79331b5</ostatus:conversation><link ref="https://social.sakamoto.gq/contexts/12a33823-0327-4c1c-a591-850ea79331b5" rel="ostatus:conversation"/><link type="application/atom+xml" href="https://social.sakamoto.gq/objects/9c5c00d7-3ce4-4c11-b965-dc5c2bda86c5" rel="self"/><link type="text/html" href="https://social.sakamoto.gq/objects/9c5c00d7-3ce4-4c11-b965-dc5c2bda86c5" rel="alternate"/><thr:in-reply-to ref="tag:mastodon.zombocloud.com,2017-08-04:objectId=995766:objectType=Status" href="https://mastodon.zombocloud.com/users/staticsafe/updates/4900"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mastodon.zombocloud.com/users/staticsafe"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/49798053-1f40-4a71-ad33-106e90630863</id><title>eal started following https://social.homunyan.com/users/animeirl</title><content type="html">eal started following https://social.homunyan.com/users/animeirl</content><published>2017-08-04T14:09:44.904792Z</published><updated>2017-08-04T14:09:44.904792Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://social.homunyan.com/users/animeirl</id><uri>https://social.homunyan.com/users/animeirl</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/49798053-1f40-4a71-ad33-106e90630863"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://social.homunyan.com/users/animeirl"/></entry><entry><activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb><id>https://social.sakamoto.gq/activities/2d83a1c5-70a6-45d3-9b84-59d6a70fbb17</id><title>New favorite by eal</title><content type="html">eal favorited something</content><published>2017-08-04T14:07:27.210044Z</published><updated>2017-08-04T14:07:27.210044Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><id>https://pleroma.soykaf.com/objects/b831e52f-4ed4-438e-95b4-888897f64f09</id></activity:object><ostatus:conversation>https://pleroma.hjkos.com/contexts/3ed48205-1e72-4e19-a618-89a0d2ca811e</ostatus:conversation><link ref="https://pleroma.hjkos.com/contexts/3ed48205-1e72-4e19-a618-89a0d2ca811e" rel="ostatus:conversation"/><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/2d83a1c5-70a6-45d3-9b84-59d6a70fbb17"/><thr:in-reply-to ref="https://pleroma.soykaf.com/objects/b831e52f-4ed4-438e-95b4-888897f64f09"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://pleroma.soykaf.com/users/lain"/></entry><entry><activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb><id>https://social.sakamoto.gq/activities/06d28bed-544a-496b-8414-1c6d439273b5</id><title>New favorite by eal</title><content type="html">eal favorited something</content><published>2017-08-04T14:05:37.280200Z</published><updated>2017-08-04T14:05:37.280200Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><id>tag:toot-lab.reclaim.technology,2017-08-04:objectId=1166030:objectType=Status</id></activity:object><ostatus:conversation>tag:p2px.me,2017-08-04:objectType=thread:nonce=f8bfc4d13db6ce91</ostatus:conversation><link ref="tag:p2px.me,2017-08-04:objectType=thread:nonce=f8bfc4d13db6ce91" rel="ostatus:conversation"/><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/06d28bed-544a-496b-8414-1c6d439273b5"/><thr:in-reply-to ref="tag:toot-lab.reclaim.technology,2017-08-04:objectId=1166030:objectType=Status"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://toot-lab.reclaim.technology/users/djsundog"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/72bf19d4-9ad4-4b2f-9cd0-f0d70f4e931b</id><title>eal started following https://mstdn.jp/users/nullkal</title><content type="html">eal started following https://mstdn.jp/users/nullkal</content><published>2017-08-04T14:05:04.148904Z</published><updated>2017-08-04T14:05:04.148904Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://mstdn.jp/users/nullkal</id><uri>https://mstdn.jp/users/nullkal</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/72bf19d4-9ad4-4b2f-9cd0-f0d70f4e931b"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mstdn.jp/users/nullkal"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb><id>https://social.sakamoto.gq/objects/b0e89515-7621-4e09-b23d-83e192324107</id><title>New note by eal</title><content type="html">&lt;a href='https://p2px.me/user/1'&gt;@stitchxd&lt;/a&gt; test also</content><published>2017-08-04T14:04:38.699051Z</published><updated>2017-08-04T14:04:38.699051Z</updated><ostatus:conversation>tag:p2px.me,2017-08-04:objectType=thread:nonce=f8bfc4d13db6ce91</ostatus:conversation><link ref="tag:p2px.me,2017-08-04:objectType=thread:nonce=f8bfc4d13db6ce91" rel="ostatus:conversation"/><link type="application/atom+xml" href="https://social.sakamoto.gq/objects/b0e89515-7621-4e09-b23d-83e192324107" rel="self"/><link type="text/html" href="https://social.sakamoto.gq/objects/b0e89515-7621-4e09-b23d-83e192324107" rel="alternate"/><thr:in-reply-to ref="tag:p2px.me,2017-08-04:noticeId=222109:objectType=note" href="https://p2px.me/notice/222109"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://p2px.me/user/1"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/></entry><entry><activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb><id>https://social.sakamoto.gq/activities/d8d2006b-6b23-45d6-ba27-39d27587777d</id><title>New favorite by eal</title><content type="html">eal favorited something</content><published>2017-08-04T14:04:32.106626Z</published><updated>2017-08-04T14:04:32.106626Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type><id>tag:p2px.me,2017-08-04:noticeId=222109:objectType=note</id></activity:object><ostatus:conversation>tag:p2px.me,2017-08-04:objectType=thread:nonce=f8bfc4d13db6ce91</ostatus:conversation><link ref="tag:p2px.me,2017-08-04:objectType=thread:nonce=f8bfc4d13db6ce91" rel="ostatus:conversation"/><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/d8d2006b-6b23-45d6-ba27-39d27587777d"/><thr:in-reply-to ref="tag:p2px.me,2017-08-04:noticeId=222109:objectType=note"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://p2px.me/user/1"/></entry><entry><activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type><activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb><id>https://social.sakamoto.gq/activities/cb9db95d-ec27-41fa-bebd-5375fc13acb9</id><title>eal started following https://mastodon.social/users/Gargron</title><content type="html">eal started following https://mastodon.social/users/Gargron</content><published>2017-08-04T14:04:04.325531Z</published><updated>2017-08-04T14:04:04.325531Z</updated><activity:object><activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type><id>https://mastodon.social/users/Gargron</id><uri>https://mastodon.social/users/Gargron</uri></activity:object><link rel="self" type="application/atom+xml" href="https://social.sakamoto.gq/activities/cb9db95d-ec27-41fa-bebd-5375fc13acb9"/><link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="https://mastodon.social/users/Gargron"/></entry></feed>
\ No newline at end of file
index 420d42a0def34a70e999ca850caa6bffeffdaaf6..08b566fcdf9672d5403b6504b4f3d3a13df06c0c 100644 (file)
@@ -87,6 +87,13 @@ defmodule HTTPoisonMock do
     }}
   end
 
+  def get("https://social.sakamoto.gq/users/eal/feed.atom", _body, _headers) do
+    {:ok, %Response{
+      status_code: 200,
+      body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
+    }}
+  end
+
   def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _body, _headers) do
     {:ok, %Response{
       status_code: 200,
@@ -142,6 +149,13 @@ defmodule HTTPoisonMock do
     }}
   end
 
+  def get("https://social.sakamoto.gq/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.sakamoto.gq/users/eal"]]) do
+    {:ok, %Response{
+      status_code: 200,
+      body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
+    }}
+  end
+
   def get("https://mamot.fr/users/Skruyb.atom", _, _) do
     {:ok, %Response{
       status_code: 200,
@@ -149,6 +163,14 @@ defmodule HTTPoisonMock do
     }}
   end
 
+  def get("https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056", [Accept: "application/atom+xml"], _) do
+    {:ok, %Response{
+      status_code: 200,
+      body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")
+    }}
+
+  end
+
   def get(url, body, headers) do
     {:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
   end
index 959b744afaa4dd2d5f5cfc1540f57a2f6d2c308d..44d687d8e9a1a1d196548edae715447c9d9ddd04 100644 (file)
@@ -326,11 +326,18 @@ defmodule Pleroma.Web.OStatusTest do
   describe "fetching a status by it's HTML url" do
     test "it builds a missing status from an html url" do
       url = "https://shitposter.club/notice/2827873"
-      {:ok, [activity] } = OStatus.fetch_activity_from_html_url(url)
+      {:ok, [activity] } = OStatus.fetch_activity_from_url(url)
 
       assert activity.data["actor"] == "https://shitposter.club/user/1"
       assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
     end
+
+    test "it works for atom notes, too" do
+      url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
+      {:ok, [activity] } = OStatus.fetch_activity_from_url(url)
+      assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
+      assert activity.data["object"]["id"] == url
+    end
   end
 
   test "insert or update a user from given data" do