diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2019-01-10 16:44:28 +0100 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2019-01-26 04:46:02 +0100 |
commit | 5a84def6a6cd6ac782e16b2aace220a99c31ace7 (patch) | |
tree | c397e00c7cc03a01a5db44a68f695339fb355ee5 /lib | |
parent | 4ad0ad14ed2d8a10bbf642fd989b3f7f55f9017d (diff) | |
download | pleroma-5a84def6a6cd6ac782e16b2aace220a99c31ace7.tar.gz |
Fix the logic in multi-hashtag TLs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 19 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 |
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 62f4a33c8..d94ad9748 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -426,15 +426,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_since(query, _), do: query - defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) - when is_list(tag) and tag_reject != [] do + defp restrict_tag_reject(query, %{"tag_reject" => tag_reject}) + when is_list(tag_reject) and tag_reject != [] do from( activity in query, - where: fragment("(? #> '{\"object\",\"tag\"}') \\?| ?", activity.data, ^tag), where: fragment("(not (? #> '{\"object\",\"tag\"}') \\?| ?)", activity.data, ^tag_reject) ) end + defp restrict_tag_reject(query, _), do: query + + defp restrict_tag_all(query, %{"tag_all" => tag_all}) + when is_list(tag_all) and tag_all != [] do + from( + activity in query, + where: fragment("(? #> '{\"object\",\"tag\"}') \\?& ?", activity.data, ^tag_all) + ) + end + + defp restrict_tag_all(query, _), do: query + defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do from( activity in query, @@ -591,6 +602,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do base_query |> restrict_recipients(recipients, opts["user"]) |> restrict_tag(opts) + |> restrict_tag_reject(opts) + |> restrict_tag_all(opts) |> restrict_since(opts) |> restrict_local(opts) |> restrict_limit(opts) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 6811f827e..4c5f1e7a9 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -541,11 +541,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do local_only = params["local"] in [true, "True", "true", "1"] tags = - ([params["tag"]] ++ (params["all"] || []) ++ (params["any"] || [])) + ([params["tag"]] ++ (params["any"] || [])) |> Enum.uniq() |> Enum.filter(& &1) |> Enum.map(&String.downcase(&1)) + tag_all = + params["all"] || + [] + |> Enum.map(&String.downcase(&1)) + tag_reject = params["none"] || [] @@ -557,6 +562,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Map.put("local_only", local_only) |> Map.put("blocking_user", user) |> Map.put("tag", tags) + |> Map.put("tag_all", tag_all) |> Map.put("tag_reject", tag_reject) activities = |