X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fuser%2Fquery.ex;h=884e33039d7453caae0166fef206df27798bc107;hb=99a6c660a909d8c74289015b3f69357196256112;hp=7f5273c4ea1cb3601bc75698b8799ea4d473ae3b;hpb=a11a7176d59deafa08a865d6e0950b9b9c540f18;p=akkoma
diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex
index 7f5273c4e..884e33039 100644
--- a/lib/pleroma/user/query.ex
+++ b/lib/pleroma/user/query.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.Query do
@@ -28,6 +28,8 @@ defmodule Pleroma.User.Query do
"""
import Ecto.Query
import Pleroma.Web.AdminAPI.Search, only: [not_empty_string: 1]
+
+ alias Pleroma.FollowingRelationship
alias Pleroma.User
@type criteria ::
@@ -46,7 +48,7 @@ defmodule Pleroma.User.Query do
followers: User.t(),
friends: User.t(),
recipients_from_activity: [String.t()],
- nickname: [String.t()],
+ nickname: [String.t()] | String.t(),
ap_id: [String.t()],
order_by: term(),
select: term(),
@@ -139,18 +141,41 @@ defmodule Pleroma.User.Query do
|> where([u], not is_nil(u.nickname))
end
- defp compose_query({:followers, %User{id: id, follower_address: follower_address}}, query) do
- where(query, [u], fragment("? <@ ?", ^[follower_address], u.following))
+ defp compose_query({:followers, %User{id: id}}, query) do
+ query
|> where([u], u.id != ^id)
+ |> join(:inner, [u], r in FollowingRelationship,
+ as: :relationships,
+ on: r.following_id == ^id and r.follower_id == u.id
+ )
+ |> where([relationships: r], r.state == "accept")
end
- defp compose_query({:friends, %User{id: id, following: following}}, query) do
- where(query, [u], u.follower_address in ^following)
+ defp compose_query({:friends, %User{id: id}}, query) do
+ query
|> where([u], u.id != ^id)
+ |> join(:inner, [u], r in FollowingRelationship,
+ as: :relationships,
+ on: r.following_id == u.id and r.follower_id == ^id
+ )
+ |> where([relationships: r], r.state == "accept")
end
defp compose_query({:recipients_from_activity, to}, query) do
- where(query, [u], u.ap_id in ^to or fragment("? && ?", u.following, ^to))
+ query
+ |> join(:left, [u], r in FollowingRelationship,
+ as: :relationships,
+ on: r.follower_id == u.id
+ )
+ |> join(:left, [relationships: r], f in User,
+ as: :following,
+ on: f.id == r.following_id
+ )
+ |> where(
+ [u, following: f, relationships: r],
+ u.ap_id in ^to or (f.follower_address in ^to and r.state == "accept")
+ )
+ |> distinct(true)
end
defp compose_query({:order_by, key}, query) do