aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLain Iwakura <lain@soykaf.club>2017-11-30 14:59:44 +0100
committerLain Iwakura <lain@soykaf.club>2017-11-30 14:59:44 +0100
commit5637d163e6eb365c69f0e79e43306156241f6494 (patch)
tree3a1988857ef2d3ad48f01633f0ba6bbcd5756082
parent9d1c0ec18dcf407bbac14868f64e98e1ec499c34 (diff)
downloadpleroma-5637d163e6eb365c69f0e79e43306156241f6494.tar.gz
MastodonAPI: Add proper user count.
-rw-r--r--lib/pleroma/user.ex5
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex3
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs15
3 files changed, 22 insertions, 1 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 68ffe184b..afc62f265 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -329,4 +329,9 @@ defmodule Pleroma.User do
Enum.member?(blocks, ap_id)
end
+ def local_user_query() do
+ from u in User,
+ where: u.local == true
+ end
+
end
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 82887966c..61bf8b4b8 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -93,6 +93,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
@instance Application.get_env(:pleroma, :instance)
def masto_instance(conn, _params) do
+ user_count = Repo.aggregate(User.local_user_query, :count, :id)
response = %{
uri: Web.base_url,
title: Keyword.get(@instance, :name),
@@ -103,8 +104,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
streaming_api: String.replace(Web.base_url, ["http","https"], "wss")
},
stats: %{
- user_count: 1,
status_count: 2,
+ user_count: user_count,
domain_count: 3
},
max_toot_chars: Keyword.get(@instance, :limit)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index c8b929501..fc0010569 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -573,4 +573,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user["header"] != "https://placehold.it/700x335"
end
end
+
+ test "get instance information" do
+ insert(:user, %{local: true})
+ user = insert(:user, %{local: true})
+ insert(:user, %{local: false})
+
+ {:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
+
+ conn = conn
+ |> get("/api/v1/instance")
+
+ assert result = json_response(conn, 200)
+
+ assert result["stats"]["user_count"] == 2
+ end
end