[Web.ActivityPub.ActivityPub]: Fix restrict_tag()
Thanks to Senko-san <kurisu@iscute.moe> for the help on array-matching
This commit is contained in:
parent
f9cae0d04f
commit
1a9bb4daa0
1 changed files with 28 additions and 5 deletions
|
@ -426,18 +426,41 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|
|
||||||
defp restrict_since(query, _), do: query
|
defp restrict_since(query, _), do: query
|
||||||
|
|
||||||
defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) when tag_reject != [] do
|
defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject})
|
||||||
|
when is_list(tag) and tag_reject != [] do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data),
|
where:
|
||||||
where: fragment("? @> (? #> '{\"object\",\"tag\"}')", ^tag_reject, activity.data)
|
fragment(
|
||||||
|
"? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}')))",
|
||||||
|
^tag,
|
||||||
|
activity.data
|
||||||
|
),
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"(not ? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))))",
|
||||||
|
^tag_reject,
|
||||||
|
activity.data
|
||||||
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_tag(query, %{"tag" => tag}) do
|
defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
activity in query,
|
||||||
where: fragment("? && jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))", ^tag, activity.data)
|
where:
|
||||||
|
fragment(
|
||||||
|
"? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}')))",
|
||||||
|
^tag,
|
||||||
|
activity.data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
|
||||||
|
from(
|
||||||
|
activity in query,
|
||||||
|
where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue