[WIP,MastoAPI] Multi-tag timelines
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 19 Dec 2018 16:21:35 +0000 (17:21 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sat, 26 Jan 2019 03:45:36 +0000 (04:45 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex

index 6b4682e35837ca04ee02ac471cd98795915b9045..e0d020fabb58723dcfb99c33f64ee3ff2d256949 100644 (file)
@@ -426,10 +426,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   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
 
index f4736fcb58cf2c0a44aa194375564c5d084a5437..6811f827eb1587f30e219bd4468888a117ba12a3 100644 (file)
@@ -540,15 +540,27 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   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