Add custom fields to TwitterAPI.UserView

This commit is contained in:
Egor Kislitsyn 2019-07-25 19:33:18 +07:00
parent 069951722f
commit a22f540fc4
2 changed files with 3 additions and 6 deletions

View File

@ -407,6 +407,8 @@ def remove_reblog_mute(info, ap_id) do
cast(info, params, [:muted_reblogs]) cast(info, params, [:muted_reblogs])
end end
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
def fields(%{source_data: %{"attachment" => attachment}}) do def fields(%{source_data: %{"attachment" => attachment}}) do
attachment attachment
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end) |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)

View File

@ -74,12 +74,7 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
|> HTML.filter_tags(User.html_filter_policy(for_user)) |> HTML.filter_tags(User.html_filter_policy(for_user))
|> Formatter.emojify(emoji) |> Formatter.emojify(emoji)
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``. fields = User.Info.fields(user.info)
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
fields =
(user.info.source_data["attachment"] || [])
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
data = data =
%{ %{