TwitterAPI: profile update with emoji_map

This commit is contained in:
Haelwenn (lanodan) Monnier 2019-02-23 00:09:11 +01:00
parent 85434669bb
commit 46bbf9e1cf
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
2 changed files with 14 additions and 3 deletions

View File

@ -654,11 +654,17 @@ defp build_info_cng(user, params) do
defp parse_profile_bio(user, params) do
if bio = params["description"] do
emojis_text = (params["description"] || "") <> " " <> (params["name"] || "")
emojis =
((user.info.emoji || []) ++ Formatter.get_emoji_map(emojis_text))
|> Enum.dedup()
user_info =
user.info
|> Map.put(
"emojis",
Formatter.get_emoji_map(params["description"])
"emoji",
emojis
)
params

View File

@ -69,6 +69,11 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
emoji = Enum.dedup(emoji ++ user.info.emoji)
description_html =
(user.bio || "")
|> HTML.filter_tags(User.html_filter_policy(for_user))
|> Formatter.emojify(emoji)
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
fields =
@ -80,7 +85,7 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
%{
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"description" => HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
"description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(for_user)),
"description_html" => description_html,
"favourites_count" => 0,
"followers_count" => user_info[:follower_count],
"following" => following,