From: ensra Date: Tue, 21 Aug 2018 13:03:36 +0000 (+0100) Subject: Twitter API: Support Mastodon-style bios X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=5debd7b5cc31a6dedd8d0c8bc177be2cd1b995aa;p=akkoma Twitter API: Support Mastodon-style bios (multi-line, with links, and user mentions) --- diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 65e67396b..dfa6d2464 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -1,7 +1,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller + alias Pleroma.Formatter alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView} alias Pleroma.Web.CommonAPI + alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils alias Pleroma.{Repo, Activity, User, Notification} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils @@ -411,8 +413,17 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def update_profile(%{assigns: %{user: user}} = conn, params) do params = if bio = params["description"] do - bio_brs = Regex.replace(~r/\r?\n/, bio, "
") - Map.put(params, "bio", bio_brs) + mentions = Formatter.parse_mentions(bio) + tags = Formatter.parse_tags(bio) + emoji = + (user.info["source_data"]["tag"] || []) + |> Enum.filter(fn %{"type" => t} -> t == "Emoji" end) + |> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} -> + {String.trim(name, ":"), url} + end) + bio_html = CommonUtils.format_input(bio, mentions, tags) + |> Formatter.emojify(emoji) + Map.put(params, "bio", bio_html) else params end diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 7d0f0e703..25fda1aa8 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -36,12 +36,10 @@ defmodule Pleroma.Web.TwitterAPI.UserView do {String.trim(name, ":"), url} end) - bio = HtmlSanitizeEx.strip_tags(user.bio) - data = %{ "created_at" => user.inserted_at |> Utils.format_naive_asctime(), - "description" => bio, - "description_html" => bio |> Formatter.emojify(emoji), + "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("
", "\n")), + "description_html" => HtmlSanitizeEx.basic_html(user.bio), "favourites_count" => 0, "followers_count" => user_info[:follower_count], "following" => following,