forked from AkkomaGang/akkoma
Use sql query in User.get_follow_requests/1 for filtering logic
This commit is contained in:
parent
f38c316e6e
commit
1a1f4520cd
2 changed files with 21 additions and 8 deletions
|
@ -648,15 +648,14 @@ def update_follow_request_count(%User{} = user) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_follow_requests(%User{} = user) do
|
def get_follow_requests(%User{} = user) do
|
||||||
q = get_follow_requests_query(user)
|
|
||||||
reqs = Repo.all(q)
|
|
||||||
|
|
||||||
users =
|
users =
|
||||||
Enum.map(reqs, fn req -> req.actor end)
|
user
|
||||||
|> Enum.uniq()
|
|> User.get_follow_requests_query()
|
||||||
|> Enum.map(fn ap_id -> get_by_ap_id(ap_id) end)
|
|> join(:inner, [a], u in User, a.actor == u.ap_id)
|
||||||
|> Enum.filter(fn u -> !is_nil(u) end)
|
|> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
|
||||||
|> Enum.filter(fn u -> !following?(u, user) end)
|
|> group_by([a, u], u.id)
|
||||||
|
|> select([a, u], u)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
{:ok, users}
|
{:ok, users}
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,20 @@ test "returns all pending follow requests" do
|
||||||
assert activity
|
assert activity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "doesn't return already accepted or duplicate follow requests" do
|
||||||
|
locked = insert(:user, %{info: %{locked: true}})
|
||||||
|
pending_follower = insert(:user)
|
||||||
|
accepted_follower = insert(:user)
|
||||||
|
|
||||||
|
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
|
||||||
|
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
|
||||||
|
Pleroma.Web.TwitterAPI.TwitterAPI.follow(accepted_follower, %{"user_id" => locked.id})
|
||||||
|
User.maybe_follow(accepted_follower, locked)
|
||||||
|
|
||||||
|
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||||
|
assert activity
|
||||||
|
end
|
||||||
|
|
||||||
test "follow_all follows mutliple users" do
|
test "follow_all follows mutliple users" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
followed_zero = insert(:user)
|
followed_zero = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue