Merge branch 'twitter-api-bios' into 'develop'
Twitter API: Support Mastodon-style bios See merge request pleroma/pleroma!283
This commit is contained in:
commit
5a8bb3cb3b
|
@ -64,7 +64,6 @@ def to_for_user_and_mentions(_user, mentions, inReplyTo, "direct") do
|
||||||
|
|
||||||
def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
|
def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
|
||||||
status
|
status
|
||||||
|> String.replace("\r", "")
|
|
||||||
|> format_input(mentions, tags)
|
|> format_input(mentions, tags)
|
||||||
|> maybe_add_attachments(attachments, no_attachment_links)
|
|> maybe_add_attachments(attachments, no_attachment_links)
|
||||||
end
|
end
|
||||||
|
@ -95,7 +94,7 @@ def add_attachments(text, attachments) do
|
||||||
def format_input(text, mentions, tags) do
|
def format_input(text, mentions, tags) do
|
||||||
text
|
text
|
||||||
|> Formatter.html_escape()
|
|> Formatter.html_escape()
|
||||||
|> String.replace("\n", "<br>")
|
|> String.replace(~r/\r?\n/, "<br>")
|
||||||
|> (&{[], &1}).()
|
|> (&{[], &1}).()
|
||||||
|> Formatter.add_links()
|
|> Formatter.add_links()
|
||||||
|> Formatter.add_user_links(mentions)
|
|> Formatter.add_user_links(mentions)
|
||||||
|
|
|
@ -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,18 @@ 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)
|
||||||
|
Map.put(params, "bio", bio_html |> Formatter.emojify(emoji))
|
||||||
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,
|
||||||
|
|
|
@ -65,8 +65,8 @@ test "A user" do
|
||||||
"name" => user.name,
|
"name" => user.name,
|
||||||
"screen_name" => user.nickname,
|
"screen_name" => user.nickname,
|
||||||
"name_html" => user.name,
|
"name_html" => user.name,
|
||||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||||
"description_html" => HtmlSanitizeEx.strip_tags(user.bio),
|
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"statuses_count" => 1,
|
"statuses_count" => 1,
|
||||||
|
@ -104,8 +104,8 @@ test "A user for a given other follower", %{user: user} do
|
||||||
"name" => user.name,
|
"name" => user.name,
|
||||||
"screen_name" => user.nickname,
|
"screen_name" => user.nickname,
|
||||||
"name_html" => user.name,
|
"name_html" => user.name,
|
||||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||||
"description_html" => HtmlSanitizeEx.strip_tags(user.bio),
|
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"statuses_count" => 0,
|
"statuses_count" => 0,
|
||||||
|
@ -144,8 +144,8 @@ test "A user that follows you", %{user: user} do
|
||||||
"name" => follower.name,
|
"name" => follower.name,
|
||||||
"screen_name" => follower.nickname,
|
"screen_name" => follower.nickname,
|
||||||
"name_html" => follower.name,
|
"name_html" => follower.name,
|
||||||
"description" => HtmlSanitizeEx.strip_tags(follower.bio),
|
"description" => HtmlSanitizeEx.strip_tags(follower.bio |> String.replace("<br>", "\n")),
|
||||||
"description_html" => HtmlSanitizeEx.strip_tags(follower.bio),
|
"description_html" => HtmlSanitizeEx.basic_html(follower.bio),
|
||||||
"created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"statuses_count" => 0,
|
"statuses_count" => 0,
|
||||||
|
@ -191,8 +191,8 @@ test "A blocked user for the blocker" do
|
||||||
"name" => user.name,
|
"name" => user.name,
|
||||||
"screen_name" => user.nickname,
|
"screen_name" => user.nickname,
|
||||||
"name_html" => user.name,
|
"name_html" => user.name,
|
||||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||||
"description_html" => HtmlSanitizeEx.strip_tags(user.bio),
|
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"statuses_count" => 0,
|
"statuses_count" => 0,
|
||||||
|
|
Loading…
Reference in New Issue