Add contact account to InstanceView
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
e3ea311cd5
commit
6b8c5e12df
1
changelog.d/instance-contact-account.add
Normal file
1
changelog.d/instance-contact-account.add
Normal file
@ -0,0 +1 @@
|
||||
Add contact account to InstanceView
|
@ -566,6 +566,12 @@ config :pleroma, :config_description, [
|
||||
"Cool instance"
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :contact_username,
|
||||
type: :string,
|
||||
description: "Instance owner username",
|
||||
suggestions: ["admin"]
|
||||
},
|
||||
%{
|
||||
key: :limit,
|
||||
type: :integer,
|
||||
|
@ -30,6 +30,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||
languages: Keyword.get(instance, :languages, ["en"]),
|
||||
registrations: Keyword.get(instance, :registrations_open),
|
||||
approval_required: Keyword.get(instance, :account_approval_required),
|
||||
contact_account: contact_account(Keyword.get(instance, :contact_username)),
|
||||
# Extra (not present in Mastodon):
|
||||
max_toot_chars: Keyword.get(instance, :limit),
|
||||
max_media_attachments: Keyword.get(instance, :max_media_attachments),
|
||||
@ -141,4 +142,20 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||
value_length: Config.get([:instance, :account_field_value_length])
|
||||
}
|
||||
end
|
||||
|
||||
defp contact_account(nil), do: nil
|
||||
|
||||
defp contact_account("@" <> username) do
|
||||
contact_account(username)
|
||||
end
|
||||
|
||||
defp contact_account(username) do
|
||||
user = Pleroma.User.get_cached_by_nickname(username)
|
||||
|
||||
if user do
|
||||
Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user, for: nil})
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -106,4 +106,16 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
||||
|> get("/api/v1/instance")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "get instance contact information", %{conn: conn} do
|
||||
user = insert(:user, %{local: true})
|
||||
|
||||
clear_config([:instance, :contact_username], user.nickname)
|
||||
|
||||
conn = get(conn, "/api/v1/instance")
|
||||
|
||||
assert result = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert result["contact_account"]["id"] == user.id
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user