[WIP,MastoAPI] Multi-tag timelines

This commit is contained in:
Haelwenn (lanodan) Monnier 2018-12-19 17:21:35 +01:00
parent 6383fa3a5d
commit f9cae0d04f
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
2 changed files with 24 additions and 4 deletions

View file

@ -426,10 +426,18 @@ defp restrict_since(query, %{"since_id" => since_id}) 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
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 defp restrict_tag(query, %{"tag" => tag}) do
from( from(
activity in query, activity in query,
where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data) where: fragment("? && jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))", ^tag, activity.data)
) )
end end

View file

@ -540,15 +540,27 @@ def reblogged_by(conn, %{"id" => id}) do
def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
local_only = params["local"] in [true, "True", "true", "1"] 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 params
|> Map.put("type", "Create") |> Map.put("type", "Create")
|> Map.put("local_only", local_only) |> Map.put("local_only", local_only)
|> Map.put("blocking_user", user) |> Map.put("blocking_user", user)
|> Map.put("tag", String.downcase(params["tag"])) |> Map.put("tag", tags)
|> Map.put("tag_reject", tag_reject)
activities = activities =
ActivityPub.fetch_public_activities(params) ActivityPub.fetch_public_activities(query_params)
|> Enum.reverse() |> Enum.reverse()
conn conn