Merge branch 'develop' into fix/pleroma-api-emoji-packs
This commit is contained in:
commit
97c60b6a43
15 changed files with 153 additions and 62 deletions
|
|
@ -156,7 +156,6 @@ defmodule Pleroma.ConfigDB do
|
|||
{:quack, :meta},
|
||||
{:mime, :types},
|
||||
{:cors_plug, [:max_age, :methods, :expose, :headers]},
|
||||
{:auto_linker, :opts},
|
||||
{:swarm, :node_blacklist},
|
||||
{:logger, :backends}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -10,11 +10,15 @@ defmodule Pleroma.Formatter do
|
|||
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
|
||||
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
||||
|
||||
@auto_linker_config hashtag: true,
|
||||
hashtag_handler: &Pleroma.Formatter.hashtag_handler/4,
|
||||
mention: true,
|
||||
mention_handler: &Pleroma.Formatter.mention_handler/4,
|
||||
scheme: true
|
||||
defp linkify_opts do
|
||||
Pleroma.Config.get(Pleroma.Formatter) ++
|
||||
[
|
||||
hashtag: true,
|
||||
hashtag_handler: &Pleroma.Formatter.hashtag_handler/4,
|
||||
mention: true,
|
||||
mention_handler: &Pleroma.Formatter.mention_handler/4
|
||||
]
|
||||
end
|
||||
|
||||
def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
|
||||
case User.get_cached_by_nickname(nickname) do
|
||||
|
|
@ -80,19 +84,19 @@ defmodule Pleroma.Formatter do
|
|||
@spec linkify(String.t(), keyword()) ::
|
||||
{String.t(), [{String.t(), User.t()}], [{String.t(), String.t()}]}
|
||||
def linkify(text, options \\ []) do
|
||||
options = options ++ @auto_linker_config
|
||||
options = linkify_opts() ++ options
|
||||
|
||||
if options[:safe_mention] && Regex.named_captures(@safe_mention_regex, text) do
|
||||
%{"mentions" => mentions, "rest" => rest} = Regex.named_captures(@safe_mention_regex, text)
|
||||
acc = %{mentions: MapSet.new(), tags: MapSet.new()}
|
||||
|
||||
{text_mentions, %{mentions: mentions}} = AutoLinker.link_map(mentions, acc, options)
|
||||
{text_rest, %{tags: tags}} = AutoLinker.link_map(rest, acc, options)
|
||||
{text_mentions, %{mentions: mentions}} = Linkify.link_map(mentions, acc, options)
|
||||
{text_rest, %{tags: tags}} = Linkify.link_map(rest, acc, options)
|
||||
|
||||
{text_mentions <> text_rest, MapSet.to_list(mentions), MapSet.to_list(tags)}
|
||||
else
|
||||
acc = %{mentions: MapSet.new(), tags: MapSet.new()}
|
||||
{text, %{mentions: mentions, tags: tags}} = AutoLinker.link_map(text, acc, options)
|
||||
{text, %{mentions: mentions, tags: tags}} = Linkify.link_map(text, acc, options)
|
||||
|
||||
{text, MapSet.to_list(mentions), MapSet.to_list(tags)}
|
||||
end
|
||||
|
|
@ -111,9 +115,9 @@ defmodule Pleroma.Formatter do
|
|||
|
||||
if options[:safe_mention] && Regex.named_captures(@safe_mention_regex, text) do
|
||||
%{"mentions" => mentions, "rest" => rest} = Regex.named_captures(@safe_mention_regex, text)
|
||||
AutoLinker.link(mentions, options) <> AutoLinker.link(rest, options)
|
||||
Linkify.link(mentions, options) <> Linkify.link(rest, options)
|
||||
else
|
||||
AutoLinker.link(text, options)
|
||||
Linkify.link(text, options)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -96,16 +96,18 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
|||
|
||||
def response("/main/public") do
|
||||
posts =
|
||||
ActivityPub.fetch_public_activities(%{"type" => ["Create"], "local_only" => true})
|
||||
|> render_activities
|
||||
%{type: ["Create"], local_only: true}
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> render_activities()
|
||||
|
||||
info("Welcome to the Public Timeline!") <> posts <> ".\r\n"
|
||||
end
|
||||
|
||||
def response("/main/all") do
|
||||
posts =
|
||||
ActivityPub.fetch_public_activities(%{"type" => ["Create"]})
|
||||
|> render_activities
|
||||
%{type: ["Create"]}
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> render_activities()
|
||||
|
||||
info("Welcome to the Federated Timeline!") <> posts <> ".\r\n"
|
||||
end
|
||||
|
|
@ -130,13 +132,14 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
|||
def response("/users/" <> nickname) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
params = %{
|
||||
"type" => ["Create"],
|
||||
"actor_id" => user.ap_id
|
||||
type: ["Create"],
|
||||
actor_id: user.ap_id
|
||||
}
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_public_activities(params)
|
||||
|> render_activities
|
||||
params
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> render_activities()
|
||||
|
||||
info("Posts by #{user.nickname}") <> activities <> ".\r\n"
|
||||
else
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ defmodule Pleroma.HTTP do
|
|||
request = build_request(method, headers, options, url, body, params)
|
||||
|
||||
adapter = Application.get_env(:tesla, :adapter)
|
||||
client = Tesla.client([Pleroma.HTTP.Middleware.FollowRedirects], adapter)
|
||||
|
||||
client = Tesla.client(adapter_middlewares(adapter), adapter)
|
||||
|
||||
maybe_limit(
|
||||
fn ->
|
||||
|
|
@ -107,4 +108,10 @@ defmodule Pleroma.HTTP do
|
|||
defp maybe_limit(fun, _, _) do
|
||||
fun.()
|
||||
end
|
||||
|
||||
defp adapter_middlewares(Tesla.Adapter.Gun) do
|
||||
[Pleroma.HTTP.Middleware.FollowRedirects]
|
||||
end
|
||||
|
||||
defp adapter_middlewares(_), do: []
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
|||
|
||||
@spec validate_page_url(URI.t() | binary()) :: :ok | :error
|
||||
defp validate_page_url(page_url) when is_binary(page_url) do
|
||||
validate_tld = Application.get_env(:auto_linker, :opts)[:validate_tld]
|
||||
validate_tld = Pleroma.Config.get([Pleroma.Formatter, :validate_tld])
|
||||
|
||||
page_url
|
||||
|> AutoLinker.Parser.url?(scheme: true, validate_tld: validate_tld)
|
||||
|> Linkify.Parser.url?(validate_tld: validate_tld)
|
||||
|> parse_uri(page_url)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue