Merge branch '491_full_mentions_in_user_bio' into 'develop'
[#491] Made user bio preserve full nicknames (nick@host) Closes #491 See merge request pleroma/pleroma!676
This commit is contained in:
commit
651ce1c97b
5 changed files with 45 additions and 15 deletions
|
|
@ -120,7 +120,7 @@ defmodule Pleroma.Formatter do
|
|||
end
|
||||
|
||||
@doc "Adds the links to mentioned users"
|
||||
def add_user_links({subs, text}, mentions) do
|
||||
def add_user_links({subs, text}, mentions, options \\ []) do
|
||||
mentions =
|
||||
mentions
|
||||
|> Enum.sort_by(fn {name, _} -> -String.length(name) end)
|
||||
|
|
@ -142,12 +142,16 @@ defmodule Pleroma.Formatter do
|
|||
ap_id
|
||||
end
|
||||
|
||||
short_match = String.split(match, "@") |> tl() |> hd()
|
||||
nickname =
|
||||
if options[:format] == :full do
|
||||
User.full_nickname(match)
|
||||
else
|
||||
User.local_nickname(match)
|
||||
end
|
||||
|
||||
{uuid,
|
||||
"<span class='h-card'><a data-user='#{id}' class='u-url mention' href='#{ap_id}'>@<span>#{
|
||||
short_match
|
||||
}</span></a></span>"}
|
||||
"<span class='h-card'><a data-user='#{id}' class='u-url mention' href='#{ap_id}'>" <>
|
||||
"@<span>#{nickname}</span></a></span>"}
|
||||
end)
|
||||
|
||||
{subs, uuid_text}
|
||||
|
|
|
|||
|
|
@ -447,8 +447,7 @@ defmodule Pleroma.User do
|
|||
def get_by_nickname(nickname) do
|
||||
Repo.get_by(User, nickname: nickname) ||
|
||||
if Regex.match?(~r(@#{Pleroma.Web.Endpoint.host()})i, nickname) do
|
||||
[local_nickname, _] = String.split(nickname, "@")
|
||||
Repo.get_by(User, nickname: local_nickname)
|
||||
Repo.get_by(User, nickname: local_nickname(nickname))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -997,7 +996,7 @@ defmodule Pleroma.User do
|
|||
end)
|
||||
|
||||
bio
|
||||
|> CommonUtils.format_input(mentions, tags, "text/plain")
|
||||
|> CommonUtils.format_input(mentions, tags, "text/plain", user_links: [format: :full])
|
||||
|> Formatter.emojify(emoji)
|
||||
end
|
||||
|
||||
|
|
@ -1048,6 +1047,16 @@ defmodule Pleroma.User do
|
|||
end
|
||||
end
|
||||
|
||||
def local_nickname(nickname_or_mention) do
|
||||
nickname_or_mention
|
||||
|> full_nickname()
|
||||
|> String.split("@")
|
||||
|> hd()
|
||||
end
|
||||
|
||||
def full_nickname(nickname_or_mention),
|
||||
do: String.trim_leading(nickname_or_mention, "@")
|
||||
|
||||
def error_user(ap_id) do
|
||||
%User{
|
||||
name: ap_id,
|
||||
|
|
|
|||
|
|
@ -116,16 +116,18 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
Enum.join([text | attachment_text], "<br>")
|
||||
end
|
||||
|
||||
def format_input(text, mentions, tags, format, options \\ [])
|
||||
|
||||
@doc """
|
||||
Formatting text to plain text.
|
||||
"""
|
||||
def format_input(text, mentions, tags, "text/plain") do
|
||||
def format_input(text, mentions, tags, "text/plain", options) do
|
||||
text
|
||||
|> Formatter.html_escape("text/plain")
|
||||
|> String.replace(~r/\r?\n/, "<br>")
|
||||
|> (&{[], &1}).()
|
||||
|> Formatter.add_links()
|
||||
|> Formatter.add_user_links(mentions)
|
||||
|> Formatter.add_user_links(mentions, options[:user_links] || [])
|
||||
|> Formatter.add_hashtag_links(tags)
|
||||
|> Formatter.finalize()
|
||||
end
|
||||
|
|
@ -133,24 +135,24 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
@doc """
|
||||
Formatting text to html.
|
||||
"""
|
||||
def format_input(text, mentions, _tags, "text/html") do
|
||||
def format_input(text, mentions, _tags, "text/html", options) do
|
||||
text
|
||||
|> Formatter.html_escape("text/html")
|
||||
|> (&{[], &1}).()
|
||||
|> Formatter.add_user_links(mentions)
|
||||
|> Formatter.add_user_links(mentions, options[:user_links] || [])
|
||||
|> Formatter.finalize()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Formatting text to markdown.
|
||||
"""
|
||||
def format_input(text, mentions, tags, "text/markdown") do
|
||||
def format_input(text, mentions, tags, "text/markdown", options) do
|
||||
text
|
||||
|> Formatter.mentions_escape(mentions)
|
||||
|> Earmark.as_html!()
|
||||
|> Formatter.html_escape("text/html")
|
||||
|> (&{[], &1}).()
|
||||
|> Formatter.add_user_links(mentions)
|
||||
|> Formatter.add_user_links(mentions, options[:user_links] || [])
|
||||
|> Formatter.add_hashtag_links(tags)
|
||||
|> Formatter.finalize()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue