forked from AkkomaGang/akkoma
Twitter API: Support Mastodon-style bios
(multi-line, with links, and user mentions)
This commit is contained in:
parent
c1b8a6a73b
commit
5debd7b5cc
2 changed files with 15 additions and 6 deletions
|
@ -1,7 +1,9 @@
|
||||||
defmodule Pleroma.Web.TwitterAPI.Controller do
|
defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
|
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
|
||||||
alias Pleroma.{Repo, Activity, User, Notification}
|
alias Pleroma.{Repo, Activity, User, Notification}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
@ -411,8 +413,17 @@ def raw_empty_array(conn, _params) do
|
||||||
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
||||||
params =
|
params =
|
||||||
if bio = params["description"] do
|
if bio = params["description"] do
|
||||||
bio_brs = Regex.replace(~r/\r?\n/, bio, "<br>")
|
mentions = Formatter.parse_mentions(bio)
|
||||||
Map.put(params, "bio", bio_brs)
|
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
|
else
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,12 +36,10 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
{String.trim(name, ":"), url}
|
{String.trim(name, ":"), url}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
bio = HtmlSanitizeEx.strip_tags(user.bio)
|
|
||||||
|
|
||||||
data = %{
|
data = %{
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"description" => bio,
|
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||||
"description_html" => bio |> Formatter.emojify(emoji),
|
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"followers_count" => user_info[:follower_count],
|
"followers_count" => user_info[:follower_count],
|
||||||
"following" => following,
|
"following" => following,
|
||||||
|
|
Loading…
Reference in a new issue