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,
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)
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"] ||
[]
|> 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 =
"tag_reject" => ["reject"]
})
+ fetch_four =
+ ActivityPub.fetch_activities([], %{
+ "tag" => ["test"],
+ "tag_all" => ["test", "reject"]
+ })
+
assert fetch_one == [status_one, status_three]
assert fetch_two == [status_one, status_two, status_three]
assert fetch_three == [status_one, status_two]
+ assert fetch_four == [status_three]
end
end
{:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"})
{:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
- all_test =
+ any_test =
conn
- |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"]})
+ |> get("/api/v1/timelines/tag/test", %{"any" => ["none"]})
- assert [status_none, status_test1, status_test] = json_response(all_test, 200)
+ [status_none, status_test1, status_test] = json_response(any_test, 200)
assert to_string(activity_test.id) == status_test["id"]
assert to_string(activity_test1.id) == status_test1["id"]
|> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
assert [status_test1, status_test] == json_response(restricted_test, 200)
+
+ all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]})
+
+ assert [status_none] == json_response(all_test, 200)
end
test "getting followers", %{conn: conn} do