diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 19 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/representers/user_representer.ex | 8 |
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 86b4b8b5e..3a4dd5d08 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1,7 +1,8 @@ defmodule Pleroma.User do use Ecto.Schema import Ecto.Changeset - alias Pleroma.{Repo, User} + import Ecto.Query + alias Pleroma.{Repo, User, Activity, Object} schema "users" do field :bio, :string @@ -32,6 +33,22 @@ defmodule Pleroma.User do |> validate_required([:following]) end + def user_info(%User{} = user) do + note_count_query = from a in Object, + where: fragment("? @> ?", a.data, ^%{actor: user.ap_id, type: "Note"}), + select: count(a.id) + + follower_count_query = from u in User, + where: fragment("? @> ?", u.following, ^User.ap_followers(user)), + select: count(u.id) + + %{ + following_count: length(user.following), + note_count: Repo.one(note_count_query), + follower_count: Repo.one(follower_count_query) + } + end + def register_changeset(struct, params \\ %{}) do changeset = struct |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation]) diff --git a/lib/pleroma/web/twitter_api/representers/user_representer.ex b/lib/pleroma/web/twitter_api/representers/user_representer.ex index 2ee4ee254..f358baf3c 100644 --- a/lib/pleroma/web/twitter_api/representers/user_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/user_representer.ex @@ -15,6 +15,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do false end + user_info = User.user_info(user) + map = %{ "id" => user.id, "name" => user.name, @@ -23,9 +25,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do "following" => following, # Fake fields "favourites_count" => 0, - "statuses_count" => 0, - "friends_count" => 0, - "followers_count" => 0, + "statuses_count" => user_info[:note_count], + "friends_count" => user_info[:following_count], + "followers_count" => user_info[:follower_count], "profile_image_url" => image, "profile_image_url_https" => image, "profile_image_url_profile_size" => image, |