account_view.ex 1.85 KB
Newer Older
lain's avatar
lain committed
1
2
3
defmodule Pleroma.Web.MastodonAPI.AccountView do
  use Pleroma.Web, :view
  alias Pleroma.User
Roger Braun's avatar
Roger Braun committed
4
  alias Pleroma.Web.MastodonAPI.AccountView
5
  alias Pleroma.Web.CommonAPI.Utils
lain's avatar
lain committed
6

lain's avatar
lain committed
7
8
9
  defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
  defp image_url(_), do: nil

10
11
12
13
  def render("accounts.json", %{users: users} = opts) do
    render_many(users, AccountView, "account.json", opts)
  end

lain's avatar
lain committed
14
15
16
17
  def render("account.json", %{user: user}) do
    image = User.avatar_url(user)
    user_info = User.user_info(user)

lain's avatar
lain committed
18
19
    header = image_url(user.info["banner"]) || "https://placehold.it/700x335"

lain's avatar
lain committed
20
21
    %{
      id: user.id,
22
      username: hd(String.split(user.nickname, "@")),
lain's avatar
lain committed
23
24
25
      acct: user.nickname,
      display_name: user.name,
      locked: false,
26
      created_at: Utils.to_masto_date(user.inserted_at),
lain's avatar
lain committed
27
28
29
      followers_count: user_info.follower_count,
      following_count: user_info.following_count,
      statuses_count: user_info.note_count,
Roger Braun's avatar
Roger Braun committed
30
      note: user.bio || "",
lain's avatar
lain committed
31
32
33
      url: user.ap_id,
      avatar: image,
      avatar_static: image,
lain's avatar
lain committed
34
      header: header,
35
36
37
38
39
40
      header_static: header,
      source: %{
        note: "",
        privacy: "public",
        sensitive: "false"
      }
lain's avatar
lain committed
41
42
    }
  end
lain's avatar
lain committed
43
44
45
46
47

  def render("mention.json", %{user: user}) do
    %{
      id: user.id,
      acct: user.nickname,
48
      username: hd(String.split(user.nickname, "@")),
lain's avatar
lain committed
49
50
51
      url: user.ap_id
    }
  end
Roger Braun's avatar
Roger Braun committed
52
53
54
55

  def render("relationship.json", %{user: user, target: target}) do
    %{
      id: target.id,
Roger Braun's avatar
Roger Braun committed
56
57
      following: User.following?(user, target),
      followed_by: User.following?(target, user),
lain's avatar
lain committed
58
      blocking: User.blocks?(user, target),
Roger Braun's avatar
Roger Braun committed
59
60
61
62
63
64
65
66
67
      muting: false,
      requested: false,
      domain_blocking: false
    }
  end

  def render("relationships.json", %{user: user, targets: targets}) do
    render_many(targets, AccountView, "relationship.json", user: user, as: :target)
  end
lain's avatar
lain committed
68
end