Merge branch 'feature/gen-magic' into 'develop'
[akkoma] / lib / pleroma / web / admin_api / controllers / admin_api_controller.ex
index 9b66c2f10f600b262985955a8979f99612de2ed9..bdd3e195d177b80b83bc21c92e792bd5c3b6ac14 100644 (file)
@@ -5,13 +5,11 @@
 defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   use Pleroma.Web, :controller
 
-  import Ecto.Query
   import Pleroma.Web.ControllerHelper, only: [json_response: 3]
 
   alias Pleroma.Config
   alias Pleroma.MFA
   alias Pleroma.ModerationLog
-  alias Pleroma.Plugs.OAuthScopesPlug
   alias Pleroma.Stats
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
@@ -22,11 +20,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   alias Pleroma.Web.AdminAPI.ModerationLogView
   alias Pleroma.Web.AdminAPI.Search
   alias Pleroma.Web.Endpoint
-  alias Pleroma.Web.PleromaAPI
+  alias Pleroma.Web.Plugs.OAuthScopesPlug
   alias Pleroma.Web.Router
 
-  require Logger
-
   @users_page_size 50
 
   plug(
@@ -267,16 +263,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   def list_user_chats(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname} = _params) do
     with %User{id: user_id} <- User.get_cached_by_nickname_or_id(nickname, for: admin) do
       chats =
-        from(c in Pleroma.Chat,
-          where: c.user_id == ^user_id,
-          order_by: [desc: c.updated_at],
-          inner_join: u in User,
-          on: u.ap_id == c.recipient
-        )
+        Pleroma.Chat.for_user_query(user_id)
         |> Pleroma.Repo.all()
 
       conn
-      |> put_view(PleromaAPI.ChatView)
+      |> put_view(AdminAPI.ChatView)
       |> render("index.json", chats: chats)
     else
       _ -> {:error, :not_found}