defp restrict_since(query, _), do: query
+ defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) when tag_reject != [] do
+ from(
+ activity in query,
+ where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data),
+ where: fragment("? @> (? #> '{\"object\",\"tag\"}')", ^tag_reject, activity.data)
+ )
+ end
+
defp restrict_tag(query, %{"tag" => tag}) do
from(
activity in query,
- where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data)
+ where: fragment("? && jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))", ^tag, activity.data)
)
end
def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
local_only = params["local"] in [true, "True", "true", "1"]
- params =
+ tags =
+ ([params["tag"]] ++ (params["all"] || []) ++ (params["any"] || []))
+ |> Enum.uniq()
+ |> Enum.filter(& &1)
+ |> Enum.map(&String.downcase(&1))
+
+ tag_reject =
+ params["none"] ||
+ []
+ |> Enum.map(&String.downcase(&1))
+
+ query_params =
params
|> Map.put("type", "Create")
|> Map.put("local_only", local_only)
|> Map.put("blocking_user", user)
- |> Map.put("tag", String.downcase(params["tag"]))
+ |> Map.put("tag", tags)
+ |> Map.put("tag_reject", tag_reject)
activities =
- ActivityPub.fetch_public_activities(params)
+ ActivityPub.fetch_public_activities(query_params)
|> Enum.reverse()
conn