MastoAPI: Add media timelines.
authoreal <eal@waifu.club>
Tue, 14 Nov 2017 13:41:16 +0000 (15:41 +0200)
committereal <eal@waifu.club>
Tue, 14 Nov 2017 13:41:16 +0000 (15:41 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index 35536a1e41cb5530886a10fbb8a6ced31c873c97..5b02fc2c6b71e952bd085b8e90342656eed4f0e5 100644 (file)
@@ -159,6 +159,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
   defp restrict_favorited_by(query, _), do: query
 
+  defp restrict_media(query, %{"only_media" => true}) do
+    from activity in query,
+      where: fragment("not (? #> '{\"object\",\"attachment\"}' = ?)", activity.data, ^[])
+  end
+  defp restrict_media(query, _), do: query
+
   # Only search through last 100_000 activities by default
   defp restrict_recent(query, %{"whole_db" => true}), do: query
   defp restrict_recent(query, _) do
@@ -191,6 +197,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> restrict_favorited_by(opts)
     |> restrict_recent(opts)
     |> restrict_blocked(opts)
+    |> restrict_media(opts)
     |> Repo.all
     |> Enum.reverse
   end
index 25d92d01038b29a41dbd2da08caf47bbbe81bec8..1b87099415734c5c787a90e28164a0d228b0ee2b 100644 (file)
@@ -249,6 +249,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
 
       assert id == to_string(note_two.id)
     end
+
+    test "gets an users media", %{conn: conn} do
+      note = insert(:note_activity)
+      user = User.get_by_ap_id(note.data["actor"])
+
+      file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
+      media = TwitterAPI.upload(file, "json")
+      |> Poison.decode!
+
+      {:ok, image_post} = TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
+
+      conn = conn
+      |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => true})
+
+      assert [%{"id" => id}] = json_response(conn, 200)
+      assert id == to_string(image_post.id)
+    end
   end
 
   describe "user relationships" do