From 46bbf9e1cff4e00f2fbd95dcc21c038d7d686b86 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 23 Feb 2019 00:09:11 +0100 Subject: [PATCH] TwitterAPI: profile update with emoji_map --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 10 ++++++++-- lib/pleroma/web/twitter_api/views/user_view.ex | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 261cc4462..ef7b6fe65 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -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 diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 6857055c9..f0a4ddbd3 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -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("
", "\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,