Move user count to stats agent.
[akkoma] / lib / pleroma / web / mastodon_api / mastodon_api_controller.ex
index fc7f210969eae6f2e72b8a968afab5e55fa78863..0615ac11a0ec26080f7396f3842d2352d6d64375 100644 (file)
@@ -1,6 +1,6 @@
 defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   use Pleroma.Web, :controller
-  alias Pleroma.{Repo, Activity, User, Notification}
+  alias Pleroma.{Repo, Activity, User, Notification, Stats}
   alias Pleroma.Web
   alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView}
   alias Pleroma.Web.ActivityPub.ActivityPub
@@ -102,17 +102,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
       urls: %{
         streaming_api: String.replace(Web.base_url, ["http","https"], "wss")
       },
-      stats: %{
-        user_count: 1,
-        status_count: 2,
-        domain_count: 3
-      },
+      stats: Stats.get_stats,
       max_toot_chars: Keyword.get(@instance, :limit)
     }
 
     json(conn, response)
   end
 
+  def peers(conn, _params) do
+    json(conn, Stats.get_peers)
+  end
+
   defp mastodonized_emoji do
     Pleroma.Formatter.get_custom_emoji()
     |> Enum.map(fn {shortcode, relative_url} ->
@@ -161,7 +161,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   def public_timeline(%{assigns: %{user: user}} = conn, params) do
     params = params
     |> Map.put("type", ["Create", "Announce"])
-    |> Map.put("local_only", !!params["local"])
+    |> Map.put("local_only", params["local"] in [true, "True", "true", "1"])
     |> Map.put("blocking_user", user)
 
     activities = ActivityPub.fetch_public_activities(params)
@@ -211,6 +211,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
     params = params
     |> Map.put("in_reply_to_status_id", params["in_reply_to_id"])
+    |> Map.put("no_attachment_links", true)
 
     {:ok, activity} = CommonAPI.post(user, params)
     render conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}
@@ -559,7 +560,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def login(conn, _) do
     conn
-    |> render(MastodonView, "login.html")
+    |> render(MastodonView, "login.html", %{error: false})
   end
 
   defp get_or_make_app() do
@@ -581,6 +582,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
       conn
       |> put_session(:oauth_token, token.token)
       |> redirect(to: "/web/getting-started")
+    else
+      _e ->
+        conn
+        |> render(MastodonView, "login.html", %{error: "Wrong username or password"})
     end
   end