diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2019-10-29 22:23:19 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2019-10-29 22:23:19 +0300 |
commit | b27a92e8faacb25540f08e32f68f37555a889aff (patch) | |
tree | e496b859774953b644008bd7d831b65d25bc7617 /lib/pleroma/user | |
parent | 922e3d082c38ccd108710e21d4bda8e65b551f9c (diff) | |
parent | eba8acff094cd63088f74424f14c9d807bb8e862 (diff) | |
download | pleroma-b27a92e8faacb25540f08e32f68f37555a889aff.tar.gz |
Merge branch 'develop' into issue/1276
Diffstat (limited to 'lib/pleroma/user')
-rw-r--r-- | lib/pleroma/user/query.ex | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex index 7f5273c4e..2eda454bc 100644 --- a/lib/pleroma/user/query.ex +++ b/lib/pleroma/user/query.ex @@ -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 :: @@ -139,18 +141,40 @@ 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") + ) end defp compose_query({:order_by, key}, query) do |