[#675] Do not show DMs in mentions timeline
This commit is contained in:
parent
1c265b3b19
commit
1341ee650e
|
@ -420,6 +420,30 @@ def fetch_public_activities(opts \\ %{}) do
|
||||||
|
|
||||||
@valid_visibilities ~w[direct unlisted public private]
|
@valid_visibilities ~w[direct unlisted public private]
|
||||||
|
|
||||||
|
defp restrict_visibility(query, %{visibility: visibility})
|
||||||
|
when is_list(visibility) do
|
||||||
|
if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
|
||||||
|
query =
|
||||||
|
from(
|
||||||
|
a in query,
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"activity_visibility(?, ?, ?) = ANY (?)",
|
||||||
|
a.actor,
|
||||||
|
a.recipients,
|
||||||
|
a.data,
|
||||||
|
^visibility
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
Ecto.Adapters.SQL.to_sql(:all, Repo, query)
|
||||||
|
|
||||||
|
query
|
||||||
|
else
|
||||||
|
Logger.error("Could not restrict visibility to #{visibility}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp restrict_visibility(query, %{visibility: visibility})
|
defp restrict_visibility(query, %{visibility: visibility})
|
||||||
when visibility in @valid_visibilities do
|
when visibility in @valid_visibilities do
|
||||||
query =
|
query =
|
||||||
|
|
|
@ -167,6 +167,7 @@ def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
params
|
params
|
||||||
|> Map.put("type", ["Create", "Announce", "Follow", "Like"])
|
|> Map.put("type", ["Create", "Announce", "Follow", "Like"])
|
||||||
|> Map.put("blocking_user", user)
|
|> Map.put("blocking_user", user)
|
||||||
|
|> Map.put(:visibility, ~w[unlisted public private])
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([user.ap_id], params)
|
activities = ActivityPub.fetch_activities([user.ap_id], params)
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,14 @@ test "it restricts by the appropriate visibility" do
|
||||||
ActivityPub.fetch_activities([], %{:visibility => "public", "actor_id" => user.ap_id})
|
ActivityPub.fetch_activities([], %{:visibility => "public", "actor_id" => user.ap_id})
|
||||||
|
|
||||||
assert activities == [public_activity]
|
assert activities == [public_activity]
|
||||||
|
|
||||||
|
activities =
|
||||||
|
ActivityPub.fetch_activities([], %{
|
||||||
|
:visibility => ~w[private public],
|
||||||
|
"actor_id" => user.ap_id
|
||||||
|
})
|
||||||
|
|
||||||
|
assert activities == [public_activity, private_activity]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -427,7 +427,10 @@ test "without valid credentials", %{conn: conn} do
|
||||||
|
|
||||||
test "with credentials", %{conn: conn, user: current_user} do
|
test "with credentials", %{conn: conn, user: current_user} do
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
|
ActivityBuilder.insert(
|
||||||
|
%{"to" => [current_user.ap_id, "https://www.w3.org/ns/activitystreams#Public"]},
|
||||||
|
%{user: current_user}
|
||||||
|
)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -445,6 +448,20 @@ test "with credentials", %{conn: conn, user: current_user} do
|
||||||
mentioned: [current_user]
|
mentioned: [current_user]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not show DMs in mentions timeline", %{conn: conn, user: current_user} do
|
||||||
|
{:ok, _activity} =
|
||||||
|
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> get("/api/statuses/mentions.json")
|
||||||
|
|
||||||
|
response = json_response(conn, 200)
|
||||||
|
|
||||||
|
assert length(response) == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /api/qvitter/statuses/notifications.json" do
|
describe "GET /api/qvitter/statuses/notifications.json" do
|
||||||
|
|
Loading…
Reference in New Issue