2017-06-19 23:12:37 +02:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.UserView do
|
|
|
|
use Pleroma.Web, :view
|
2017-03-23 15:51:34 +01:00
|
|
|
alias Pleroma.User
|
2017-06-19 23:12:37 +02:00
|
|
|
alias Pleroma.Web.TwitterAPI.Utils
|
2017-03-23 15:51:34 +01:00
|
|
|
|
2017-06-19 23:12:37 +02:00
|
|
|
def render("show.json", %{user: user = %User{}} = assigns) do
|
2017-04-17 14:12:36 +02:00
|
|
|
image = User.avatar_url(user)
|
2017-06-19 23:12:37 +02:00
|
|
|
following = if assigns[:for] do
|
|
|
|
User.following?(assigns[:for], user)
|
2017-03-23 15:51:34 +01:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-04-30 10:04:54 +02:00
|
|
|
user_info = User.get_cached_user_info(user)
|
2017-04-21 00:51:09 +02:00
|
|
|
|
2017-06-19 23:12:37 +02:00
|
|
|
%{
|
|
|
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
|
2017-06-18 13:17:35 +02:00
|
|
|
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
2017-03-20 21:30:18 +01:00
|
|
|
"favourites_count" => 0,
|
2017-04-21 00:51:09 +02:00
|
|
|
"followers_count" => user_info[:follower_count],
|
2017-06-19 23:12:37 +02:00
|
|
|
"following" => following,
|
|
|
|
"friends_count" => user_info[:following_count],
|
|
|
|
"id" => user.id,
|
|
|
|
"name" => user.name,
|
2017-03-20 21:30:18 +01:00
|
|
|
"profile_image_url" => image,
|
|
|
|
"profile_image_url_https" => image,
|
|
|
|
"profile_image_url_profile_size" => image,
|
|
|
|
"profile_image_url_original" => image,
|
2017-05-02 14:36:04 +02:00
|
|
|
"rights" => %{},
|
2017-06-19 23:12:37 +02:00
|
|
|
"screen_name" => user.nickname,
|
|
|
|
"statuses_count" => user_info[:note_count],
|
2017-05-02 14:36:04 +02:00
|
|
|
"statusnet_profile_url" => user.ap_id
|
2017-03-20 21:30:18 +01:00
|
|
|
}
|
2017-06-19 23:12:37 +02:00
|
|
|
end
|
2017-03-20 21:30:18 +01:00
|
|
|
|
2017-06-19 23:12:37 +02:00
|
|
|
def render("short.json", %{user: %User{
|
|
|
|
nickname: nickname, id: id, ap_id: ap_id, name: name
|
|
|
|
}}) do
|
|
|
|
%{
|
|
|
|
"fullname" => name,
|
|
|
|
"id" => id,
|
|
|
|
"ostatus_uri" => ap_id,
|
|
|
|
"profile_url" => ap_id,
|
|
|
|
"screen_name" => nickname
|
|
|
|
}
|
2017-03-20 21:30:18 +01:00
|
|
|
end
|
|
|
|
end
|