qb_akkoma/lib/pleroma/web/twitter_api/views/user_view.ex

67 lines
2.1 KiB
Elixir
Raw Normal View History

2017-06-19 21:12:37 +00:00
defmodule Pleroma.Web.TwitterAPI.UserView do
use Pleroma.Web, :view
alias Pleroma.User
alias Pleroma.Web.CommonAPI.Utils
2017-06-19 21:12:37 +00:00
def render("show.json", %{user: user = %User{}} = assigns) do
2017-07-20 18:29:15 +00:00
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
end
def render("index.json", %{users: users, for: user}) do
render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
end
2017-08-29 15:18:33 +00:00
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
defp image_url(_), do: nil
2017-07-20 18:29:15 +00:00
def render("user.json", %{user: user = %User{}} = assigns) do
2017-04-17 12:12:36 +00:00
image = User.avatar_url(user)
2017-11-08 17:13:03 +00:00
{following, follows_you, statusnet_blocking} = if assigns[:for] do
{
User.following?(assigns[:for], user),
User.following?(user, assigns[:for]),
User.blocks?(assigns[:for], user)
}
else
2017-11-08 17:13:03 +00:00
{false, false, false}
2017-11-08 11:02:00 +00:00
end
user_info = User.get_cached_user_info(user)
2017-04-20 22:51:09 +00:00
2017-06-19 21:12:37 +00:00
%{
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
2017-03-20 20:30:18 +00:00
"favourites_count" => 0,
2017-04-20 22:51:09 +00:00
"followers_count" => user_info[:follower_count],
2017-06-19 21:12:37 +00:00
"following" => following,
2017-11-08 17:13:03 +00:00
"follows_you" => follows_you,
2017-11-08 11:02:00 +00:00
"statusnet_blocking" => statusnet_blocking,
2017-06-19 21:12:37 +00:00
"friends_count" => user_info[:following_count],
"id" => user.id,
"name" => user.name,
2017-03-20 20:30:18 +00:00
"profile_image_url" => image,
"profile_image_url_https" => image,
"profile_image_url_profile_size" => image,
"profile_image_url_original" => image,
"rights" => %{},
2017-06-19 21:12:37 +00:00
"screen_name" => user.nickname,
"statuses_count" => user_info[:note_count],
2017-08-29 15:18:33 +00:00
"statusnet_profile_url" => user.ap_id,
"cover_photo" => image_url(user.info["banner"]),
"background_image" => image_url(user.info["background"])
2017-03-20 20:30:18 +00:00
}
2017-06-19 21:12:37 +00:00
end
2017-03-20 20:30:18 +00:00
2017-06-19 21:12:37 +00: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 20:30:18 +00:00
end
end