akkoma/lib/pleroma/web/twitter_api/representers/user_representer.ex

41 lines
1 KiB
Elixir
Raw Normal View History

2017-03-20 20:30:18 +00:00
defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
alias Pleroma.User
def to_map(user, opts) do
image = case user.avatar do
%{"url" => [%{"href" => href} | _]} -> href
_ -> "https://placehold.it/48x48"
end
following = if opts[:for] do
User.following?(opts[:for], user)
else
false
end
2017-04-20 22:51:09 +00:00
user_info = User.user_info(user)
2017-03-20 20:30:18 +00:00
map = %{
"id" => user.id,
"name" => user.name,
"screen_name" => user.nickname,
"description" => user.bio,
"following" => following,
2017-03-20 20:30:18 +00:00
# Fake fields
"favourites_count" => 0,
2017-04-20 22:51:09 +00:00
"statuses_count" => user_info[:note_count],
"friends_count" => user_info[:following_count],
"followers_count" => user_info[:follower_count],
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" => %{}
}
map
end
end