account_view.ex 1.84 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
href's avatar
href committed
6
  alias Pleroma.Web.MediaProxy
lain's avatar
lain committed
7

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

lain's avatar
lain committed
12
  def render("account.json", %{user: user}) do
href's avatar
href committed
13
    image = User.avatar_url(user) |> MediaProxy.url()
14
    header = User.banner_url(user) |> MediaProxy.url()
lain's avatar
lain committed
15
16
17
    user_info = User.user_info(user)

    %{
lain's avatar
lain committed
18
      id: to_string(user.id),
19
      username: hd(String.split(user.nickname, "@")),
lain's avatar
lain committed
20
      acct: user.nickname,
21
      display_name: user.name || user.nickname,
22
      locked: user_info.locked,
23
      created_at: Utils.to_masto_date(user.inserted_at),
lain's avatar
lain committed
24
25
26
      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
27
      note: user.bio || "",
lain's avatar
lain committed
28
29
30
      url: user.ap_id,
      avatar: image,
      avatar_static: image,
lain's avatar
lain committed
31
      header: header,
32
33
34
35
36
37
      header_static: header,
      source: %{
        note: "",
        privacy: "public",
        sensitive: "false"
      }
lain's avatar
lain committed
38
39
    }
  end
lain's avatar
lain committed
40
41
42

  def render("mention.json", %{user: user}) do
    %{
lain's avatar
lain committed
43
      id: to_string(user.id),
lain's avatar
lain committed
44
      acct: user.nickname,
45
      username: hd(String.split(user.nickname, "@")),
lain's avatar
lain committed
46
47
48
      url: user.ap_id
    }
  end
Roger Braun's avatar
Roger Braun committed
49
50
51

  def render("relationship.json", %{user: user, target: target}) do
    %{
lain's avatar
lain committed
52
      id: to_string(target.id),
Roger Braun's avatar
Roger Braun committed
53
54
      following: User.following?(user, target),
      followed_by: User.following?(target, user),
lain's avatar
lain committed
55
      blocking: User.blocks?(user, target),
Roger Braun's avatar
Roger Braun committed
56
57
58
59
60
61
62
63
64
      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
65
end