Use the preloaded object in tag queries
This commit is contained in:
parent
35ac672b8d
commit
2abc09570f
|
@ -574,8 +574,8 @@ defp restrict_since(query, _), do: query
|
||||||
defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
|
defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
|
||||||
when is_list(tag_reject) and tag_reject != [] do
|
when is_list(tag_reject) and tag_reject != [] do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
[_activity, object] in query,
|
||||||
where: fragment(~s(\(not \(? #> '{"object","tag"}'\) \\?| ?\)), activity.data, ^tag_reject)
|
where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -584,8 +584,8 @@ defp restrict_tag_reject(query, _), do: query
|
||||||
defp restrict_tag_all(query, %{"tag_all" => tag_all})
|
defp restrict_tag_all(query, %{"tag_all" => tag_all})
|
||||||
when is_list(tag_all) and tag_all != [] do
|
when is_list(tag_all) and tag_all != [] do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
[_activity, object] in query,
|
||||||
where: fragment(~s(\(? #> '{"object","tag"}'\) \\?& ?), activity.data, ^tag_all)
|
where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -593,15 +593,15 @@ defp restrict_tag_all(query, _), do: query
|
||||||
|
|
||||||
defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
|
defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
[_activity, object] in query,
|
||||||
where: fragment(~s(\(? #> '{"object","tag"}'\) \\?| ?), activity.data, ^tag)
|
where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
|
defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
[_activity, object] in query,
|
||||||
where: fragment(~s(? <@ (? #> '{"object","tag"}'\)), ^tag, activity.data)
|
where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -84,17 +84,21 @@ test "it fetches the appropriate tag-restricted posts" do
|
||||||
{:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"})
|
{:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"})
|
||||||
{:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"})
|
{:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"})
|
||||||
|
|
||||||
fetch_one = ActivityPub.fetch_activities([], %{"tag" => "test"})
|
fetch_one = ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => "test"})
|
||||||
fetch_two = ActivityPub.fetch_activities([], %{"tag" => ["test", "essais"]})
|
|
||||||
|
fetch_two =
|
||||||
|
ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => ["test", "essais"]})
|
||||||
|
|
||||||
fetch_three =
|
fetch_three =
|
||||||
ActivityPub.fetch_activities([], %{
|
ActivityPub.fetch_activities([], %{
|
||||||
|
"type" => "Create",
|
||||||
"tag" => ["test", "essais"],
|
"tag" => ["test", "essais"],
|
||||||
"tag_reject" => ["reject"]
|
"tag_reject" => ["reject"]
|
||||||
})
|
})
|
||||||
|
|
||||||
fetch_four =
|
fetch_four =
|
||||||
ActivityPub.fetch_activities([], %{
|
ActivityPub.fetch_activities([], %{
|
||||||
|
"type" => "Create",
|
||||||
"tag" => ["test"],
|
"tag" => ["test"],
|
||||||
"tag_all" => ["test", "reject"]
|
"tag_all" => ["test", "reject"]
|
||||||
})
|
})
|
||||||
|
@ -832,6 +836,7 @@ test "it filters broken threads" do
|
||||||
activities = ActivityPub.fetch_activities([user1.ap_id | user1.following])
|
activities = ActivityPub.fetch_activities([user1.ap_id | user1.following])
|
||||||
|
|
||||||
private_activity_1 = Activity.get_by_ap_id_with_object(private_activity_1.data["id"])
|
private_activity_1 = Activity.get_by_ap_id_with_object(private_activity_1.data["id"])
|
||||||
|
|
||||||
assert [public_activity, private_activity_1, private_activity_3] ==
|
assert [public_activity, private_activity_1, private_activity_3] ==
|
||||||
activities
|
activities
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue