Replace UserRepresenter with UserView
This commit is contained in:
parent
45c751985e
commit
069daf644d
10 changed files with 90 additions and 96 deletions
47
lib/pleroma/web/twitter_api/views/user_view.ex
Normal file
47
lib/pleroma/web/twitter_api/views/user_view.ex
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.UserView do
|
||||
use Pleroma.Web, :view
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.TwitterAPI.Utils
|
||||
|
||||
def render("show.json", %{user: user = %User{}} = assigns) do
|
||||
image = User.avatar_url(user)
|
||||
following = if assigns[:for] do
|
||||
User.following?(assigns[:for], user)
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
user_info = User.get_cached_user_info(user)
|
||||
|
||||
%{
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
||||
"favourites_count" => 0,
|
||||
"followers_count" => user_info[:follower_count],
|
||||
"following" => following,
|
||||
"friends_count" => user_info[:following_count],
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"rights" => %{},
|
||||
"screen_name" => user.nickname,
|
||||
"statuses_count" => user_info[:note_count],
|
||||
"statusnet_profile_url" => user.ap_id
|
||||
}
|
||||
end
|
||||
|
||||
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
|
||||
}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue