add visibility check on quote (#178)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/178
This commit is contained in:
parent
429e2ac832
commit
d72f9e39d9
|
@ -623,15 +623,19 @@ defp build_image_url(_, _), do: nil
|
||||||
defp maybe_render_quote(nil, _), do: nil
|
defp maybe_render_quote(nil, _), do: nil
|
||||||
|
|
||||||
defp maybe_render_quote(quote, opts) do
|
defp maybe_render_quote(quote, opts) do
|
||||||
if opts[:do_not_recurse] || !visible_for_user?(quote, opts[:for]) do
|
with %User{} = quoted_user <- User.get_cached_by_ap_id(quote.actor),
|
||||||
nil
|
false <- Map.get(opts, :do_not_recurse, false),
|
||||||
else
|
true <- visible_for_user?(quote, opts[:for]),
|
||||||
|
false <- User.blocks?(opts[:for], quoted_user),
|
||||||
|
false <- User.mutes?(opts[:for], quoted_user) do
|
||||||
opts =
|
opts =
|
||||||
opts
|
opts
|
||||||
|> Map.put(:activity, quote)
|
|> Map.put(:activity, quote)
|
||||||
|> Map.put(:do_not_recurse, true)
|
|> Map.put(:do_not_recurse, true)
|
||||||
|
|
||||||
render("show.json", opts)
|
render("show.json", opts)
|
||||||
|
else
|
||||||
|
_ -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -428,6 +428,34 @@ test "a quote that we can't resolve" do
|
||||||
assert is_nil(status.quote)
|
assert is_nil(status.quote)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "a quote from a user we block" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
blocked_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, _relationship} = User.block(user, blocked_user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(blocked_user, %{status: ":< i am ANGERY"})
|
||||||
|
{:ok, quote_activity} = CommonAPI.post(other_user, %{status: "hehe", quote_id: activity.id})
|
||||||
|
|
||||||
|
status = StatusView.render("show.json", %{activity: quote_activity, for: user})
|
||||||
|
assert is_nil(status.quote)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a quote from a user we mute" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
blocked_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, _relationship} = User.mute(user, blocked_user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(blocked_user, %{status: ":< i am ANGERY"})
|
||||||
|
{:ok, quote_activity} = CommonAPI.post(other_user, %{status: "hehe", quote_id: activity.id})
|
||||||
|
|
||||||
|
status = StatusView.render("show.json", %{activity: quote_activity, for: user})
|
||||||
|
assert is_nil(status.quote)
|
||||||
|
end
|
||||||
|
|
||||||
test "contains mentions" do
|
test "contains mentions" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
mentioned = insert(:user)
|
mentioned = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue