expanding filtration for home timeline
added local & remote statuses filtration for home timeline
This commit is contained in:
parent
08a2cb750d
commit
c3110c46f3
@ -735,6 +735,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|
|
||||||
defp restrict_local(query, _), do: query
|
defp restrict_local(query, _), do: query
|
||||||
|
|
||||||
|
defp restrict_remote(query, %{only_remote: true}) do
|
||||||
|
from(activity in query, where: activity.local == false)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_remote(query, _), do: query
|
||||||
|
|
||||||
defp restrict_actor(query, %{actor_id: actor_id}) do
|
defp restrict_actor(query, %{actor_id: actor_id}) do
|
||||||
from(activity in query, where: activity.actor == ^actor_id)
|
from(activity in query, where: activity.actor == ^actor_id)
|
||||||
end
|
end
|
||||||
@ -1111,6 +1117,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|> restrict_tag_all(opts)
|
|> restrict_tag_all(opts)
|
||||||
|> restrict_since(opts)
|
|> restrict_since(opts)
|
||||||
|> restrict_local(opts)
|
|> restrict_local(opts)
|
||||||
|
|> restrict_remote(opts)
|
||||||
|> restrict_actor(opts)
|
|> restrict_actor(opts)
|
||||||
|> restrict_type(opts)
|
|> restrict_type(opts)
|
||||||
|> restrict_state(opts)
|
|> restrict_state(opts)
|
||||||
|
@ -25,6 +25,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||||||
security: [%{"oAuth" => ["read:statuses"]}],
|
security: [%{"oAuth" => ["read:statuses"]}],
|
||||||
parameters: [
|
parameters: [
|
||||||
local_param(),
|
local_param(),
|
||||||
|
remote_param(),
|
||||||
with_muted_param(),
|
with_muted_param(),
|
||||||
exclude_visibilities_param(),
|
exclude_visibilities_param(),
|
||||||
reply_visibility_param() | pagination_params()
|
reply_visibility_param() | pagination_params()
|
||||||
@ -198,4 +199,13 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
|
|||||||
"Show only statuses with media attached?"
|
"Show only statuses with media attached?"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp remote_param do
|
||||||
|
Operation.parameter(
|
||||||
|
:only_remote,
|
||||||
|
:query,
|
||||||
|
%Schema{allOf: [BooleanLike], default: false},
|
||||||
|
"Show only remote statuses?"
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -51,6 +51,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
|||||||
|> Map.put(:reply_filtering_user, user)
|
|> Map.put(:reply_filtering_user, user)
|
||||||
|> Map.put(:announce_filtering_user, user)
|
|> Map.put(:announce_filtering_user, user)
|
||||||
|> Map.put(:user, user)
|
|> Map.put(:user, user)
|
||||||
|
|> Map.put(:local_only, params[:local])
|
||||||
|
|> Map.delete(:local)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
[user.ap_id | User.following(user)]
|
[user.ap_id | User.following(user)]
|
||||||
|
@ -90,6 +90,82 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||||||
}
|
}
|
||||||
] = result
|
] = result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "local/remote filtering", %{conn: conn, user: user} do
|
||||||
|
local = insert(:user)
|
||||||
|
remote = insert(:user, local: false)
|
||||||
|
|
||||||
|
{:ok, user, local} = User.follow(user, local)
|
||||||
|
{:ok, _user, remote} = User.follow(user, remote)
|
||||||
|
|
||||||
|
object1 =
|
||||||
|
insert(:note, %{
|
||||||
|
data: %{
|
||||||
|
"to" => ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(local)]
|
||||||
|
},
|
||||||
|
user: local
|
||||||
|
})
|
||||||
|
|
||||||
|
activity1 =
|
||||||
|
insert(:note_activity, %{
|
||||||
|
note: object1,
|
||||||
|
recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(local)],
|
||||||
|
user: local
|
||||||
|
})
|
||||||
|
|
||||||
|
object2 =
|
||||||
|
insert(:note, %{
|
||||||
|
data: %{
|
||||||
|
"to" => ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(remote)]
|
||||||
|
},
|
||||||
|
user: remote
|
||||||
|
})
|
||||||
|
|
||||||
|
activity2 =
|
||||||
|
insert(:note_activity, %{
|
||||||
|
note: object2,
|
||||||
|
recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(remote)],
|
||||||
|
user: remote,
|
||||||
|
local: false
|
||||||
|
})
|
||||||
|
|
||||||
|
resp1 =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/timelines/home")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
without_filter_ids = Enum.map(resp1, & &1["id"])
|
||||||
|
|
||||||
|
assert activity1.id in without_filter_ids
|
||||||
|
assert activity2.id in without_filter_ids
|
||||||
|
|
||||||
|
resp2 =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/timelines/home?local=true")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
only_local_ids = Enum.map(resp2, & &1["id"])
|
||||||
|
|
||||||
|
assert activity1.id in only_local_ids
|
||||||
|
refute activity2.id in only_local_ids
|
||||||
|
|
||||||
|
resp3 =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/timelines/home?only_remote=true")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
only_remote_ids = Enum.map(resp3, & &1["id"])
|
||||||
|
|
||||||
|
refute activity1.id in only_remote_ids
|
||||||
|
assert activity2.id in only_remote_ids
|
||||||
|
|
||||||
|
resp4 =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/timelines/home?only_remote=true&local=true")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert resp4 == []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "public" do
|
describe "public" do
|
||||||
|
Loading…
Reference in New Issue
Block a user