forked from AkkomaGang/akkoma
Allow restricting public timeline by instance
This commit is contained in:
parent
10d46235cf
commit
afa8b469ed
4 changed files with 25 additions and 10 deletions
|
@ -927,16 +927,8 @@ defp restrict_muted_reblogs(query, %{muting_user: %User{} = user} = opts) do
|
||||||
|
|
||||||
defp restrict_muted_reblogs(query, _), do: query
|
defp restrict_muted_reblogs(query, _), do: query
|
||||||
|
|
||||||
defp restrict_instance(query, %{instance: instance}) do
|
defp restrict_instance(query, %{instance: instance}) when is_binary(instance) do
|
||||||
users =
|
from(activity in query, where: ilike(activity.actor, ^"%://#{instance}/%"))
|
||||||
from(
|
|
||||||
u in User,
|
|
||||||
select: u.ap_id,
|
|
||||||
where: fragment("? LIKE ?", u.nickname, ^"%@#{instance}")
|
|
||||||
)
|
|
||||||
|> Repo.all()
|
|
||||||
|
|
||||||
from(activity in query, where: activity.actor in ^users)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_instance(query, _), do: query
|
defp restrict_instance(query, _), do: query
|
||||||
|
|
|
@ -59,6 +59,7 @@ def public_operation do
|
||||||
security: [%{"oAuth" => ["read:statuses"]}],
|
security: [%{"oAuth" => ["read:statuses"]}],
|
||||||
parameters: [
|
parameters: [
|
||||||
local_param(),
|
local_param(),
|
||||||
|
instance_param(),
|
||||||
only_media_param(),
|
only_media_param(),
|
||||||
with_muted_param(),
|
with_muted_param(),
|
||||||
exclude_visibilities_param(),
|
exclude_visibilities_param(),
|
||||||
|
@ -158,6 +159,15 @@ defp local_param do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp instance_param do
|
||||||
|
Operation.parameter(
|
||||||
|
:instance,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :string},
|
||||||
|
"Show only statuses from the given domain"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
defp with_muted_param do
|
defp with_muted_param do
|
||||||
Operation.parameter(:with_muted, :query, BooleanLike, "Includeactivities by muted users")
|
Operation.parameter(:with_muted, :query, BooleanLike, "Includeactivities by muted users")
|
||||||
end
|
end
|
||||||
|
|
|
@ -110,6 +110,7 @@ def public(%{assigns: %{user: user}} = conn, params) do
|
||||||
|> Map.put(:blocking_user, user)
|
|> Map.put(:blocking_user, user)
|
||||||
|> Map.put(:muting_user, user)
|
|> Map.put(:muting_user, user)
|
||||||
|> Map.put(:reply_filtering_user, user)
|
|> Map.put(:reply_filtering_user, user)
|
||||||
|
|> Map.put(:instance, params[:instance])
|
||||||
|> ActivityPub.fetch_public_activities()
|
|> ActivityPub.fetch_public_activities()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -140,6 +140,18 @@ test "doesn't return replies if follow is posting with users from blocked domain
|
||||||
activities = json_response_and_validate_schema(res_conn, 200)
|
activities = json_response_and_validate_schema(res_conn, 200)
|
||||||
[%{"id" => ^activity_id}] = activities
|
[%{"id" => ^activity_id}] = activities
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "can be filtered by instance", %{conn: conn} do
|
||||||
|
user = insert(:user, ap_id: "https://lain.com/users/lain")
|
||||||
|
insert(:note_activity, local: false)
|
||||||
|
insert(:note_activity, local: false)
|
||||||
|
|
||||||
|
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||||
|
|
||||||
|
conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
|
||||||
|
|
||||||
|
assert length(json_response_and_validate_schema(conn, :ok)) == 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp local_and_remote_activities do
|
defp local_and_remote_activities do
|
||||||
|
|
Loading…
Reference in a new issue