ActivityPub: When restricting to media posts, only show 'Creates'.

This commit is contained in:
lain 2020-06-16 13:08:27 +02:00
parent 1e49bfa9ac
commit 1eb6cedaad
2 changed files with 11 additions and 2 deletions

View File

@ -833,7 +833,8 @@ defp restrict_media(_query, %{only_media: _val, skip_preload: true}) do
defp restrict_media(query, %{only_media: true}) do defp restrict_media(query, %{only_media: true}) do
from( from(
[_activity, object] in query, [activity, object] in query,
where: fragment("(?)->>'type' = ?", activity.data, "Create"),
where: fragment("not (?)->'attachment' = (?)", object.data, ^[]) where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
) )
end end

View File

@ -350,9 +350,10 @@ test "unimplemented pinned statuses feature", %{conn: conn} do
assert json_response_and_validate_schema(conn, 200) == [] assert json_response_and_validate_schema(conn, 200) == []
end end
test "gets an users media", %{conn: conn} do test "gets an users media, excludes reblogs", %{conn: conn} do
note = insert(:note_activity) note = insert(:note_activity)
user = User.get_cached_by_ap_id(note.data["actor"]) user = User.get_cached_by_ap_id(note.data["actor"])
other_user = insert(:user)
file = %Plug.Upload{ file = %Plug.Upload{
content_type: "image/jpg", content_type: "image/jpg",
@ -364,6 +365,13 @@ test "gets an users media", %{conn: conn} do
{:ok, %{id: image_post_id}} = CommonAPI.post(user, %{status: "cofe", media_ids: [media_id]}) {: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") conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?only_media=true")
assert [%{"id" => ^image_post_id}] = json_response_and_validate_schema(conn, 200) assert [%{"id" => ^image_post_id}] = json_response_and_validate_schema(conn, 200)