ActivityPub: When restricting to media posts, only show 'Creates'.
authorlain <lain@soykaf.club>
Tue, 16 Jun 2020 11:08:27 +0000 (13:08 +0200)
committerlain <lain@soykaf.club>
Tue, 16 Jun 2020 11:08:27 +0000 (13:08 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/mastodon_api/controllers/account_controller_test.exs

index c9dc6135cd426d9a83e35d7317ee8a50421b95f3..efb8b81dbce54da43b656ae4965b7b56e08e021f 100644 (file)
@@ -833,7 +833,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp restrict_media(query, %{only_media: true}) do
     from(
-      [_activity, object] in query,
+      [activity, object] in query,
+      where: fragment("(?)->>'type' = ?", activity.data, "Create"),
       where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
     )
   end
index 1ce97378d18fabe0f7a106503839d9f156c580e5..2343a9d2d0dee2a58d0df7fe2d085780a9be32a9 100644 (file)
@@ -350,9 +350,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
       assert json_response_and_validate_schema(conn, 200) == []
     end
 
-    test "gets an users media", %{conn: conn} do
+    test "gets an users media, excludes reblogs", %{conn: conn} do
       note = insert(:note_activity)
       user = User.get_cached_by_ap_id(note.data["actor"])
+      other_user = insert(:user)
 
       file = %Plug.Upload{
         content_type: "image/jpg",
@@ -364,6 +365,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
       {:ok, %{id: image_post_id}} = CommonAPI.post(user, %{status: "cofe", media_ids: [media_id]})
 
+      {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: other_user.ap_id)
+
+      {:ok, %{id: other_image_post_id}} =
+        CommonAPI.post(other_user, %{status: "cofe2", media_ids: [media_id]})
+
+      {:ok, _announce} = CommonAPI.repeat(other_image_post_id, user)
+
       conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?only_media=true")
 
       assert [%{"id" => ^image_post_id}] = json_response_and_validate_schema(conn, 200)