#{
@@ -70,6 +81,25 @@ def linkify(text, options \\ []) do
end
end
+ @doc """
+ Escapes a special characters in mention names.
+ """
+ def mentions_escape(text, options \\ []) do
+ options =
+ Keyword.merge(options,
+ mention: true,
+ url: false,
+ mention_handler: &Pleroma.Formatter.escape_mention_handler/4
+ )
+
+ 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)
+ else
+ AutoLinker.link(text, options)
+ end
+ end
+
def emojify(text) do
emojify(text, Emoji.get_all())
end
@@ -140,10 +170,4 @@ defp get_ap_id(%User{ap_id: ap_id}), do: ap_id
defp get_nickname_text(nickname, %{mentions_format: :full}), do: User.full_nickname(nickname)
defp get_nickname_text(nickname, _), do: User.local_nickname(nickname)
-
- defp maybe_escape(str, %{mentions_escape: true}) do
- String.replace(str, @markdown_characters_regex, "\\\\\\1")
- end
-
- defp maybe_escape(str, _), do: str
end
diff --git a/lib/pleroma/pagination.ex b/lib/pleroma/pagination.ex
index 7c864deef..f435e5c9c 100644
--- a/lib/pleroma/pagination.ex
+++ b/lib/pleroma/pagination.ex
@@ -36,6 +36,12 @@ defp cast_params(params) do
limit: :integer
}
+ params =
+ Enum.reduce(params, %{}, fn
+ {key, _value}, acc when is_atom(key) -> Map.drop(acc, [key])
+ {key, value}, acc -> Map.put(acc, key, value)
+ end)
+
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
changeset.changes
end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 6e2269aff..4a41a15c7 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -279,8 +279,8 @@ def try_send_confirmation_email(%User{} = user) do
if user.info.confirmation_pending &&
Pleroma.Config.get([:instance, :account_activation_required]) do
user
- |> Pleroma.UserEmail.account_confirmation_email()
- |> Pleroma.Mailer.deliver_async()
+ |> Pleroma.Emails.UserEmail.account_confirmation_email()
+ |> Pleroma.Emails.Mailer.deliver_async()
else
{:ok, :noop}
end
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index f217e7bac..89fee2d9f 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.Instances
alias Pleroma.Notification
alias Pleroma.Object
+ alias Pleroma.Pagination
alias Pleroma.Repo
alias Pleroma.Upload
alias Pleroma.User
@@ -449,8 +450,8 @@ def flag(
:ok <- maybe_federate(activity) do
Enum.each(User.all_superusers(), fn superuser ->
superuser
- |> Pleroma.AdminEmail.report(actor, account, statuses, content)
- |> Pleroma.Mailer.deliver_async()
+ |> Pleroma.Emails.AdminEmail.report(actor, account, statuses, content)
+ |> Pleroma.Emails.Mailer.deliver_async()
end)
{:ok, activity}
@@ -493,7 +494,7 @@ def fetch_public_activities(opts \\ %{}) do
q
|> restrict_unlisted()
- |> Repo.all()
+ |> Pagination.fetch_paginated(opts)
|> Enum.reverse()
end
@@ -636,26 +637,12 @@ defp restrict_recipients(query, recipients, user) do
)
end
- defp restrict_limit(query, %{"limit" => limit}) do
- from(activity in query, limit: ^limit)
- end
-
- defp restrict_limit(query, _), do: query
-
defp restrict_local(query, %{"local_only" => true}) do
from(activity in query, where: activity.local == true)
end
defp restrict_local(query, _), do: query
- defp restrict_max(query, %{"max_id" => ""}), do: query
-
- defp restrict_max(query, %{"max_id" => max_id}) do
- from(activity in query, where: activity.id < ^max_id)
- end
-
- defp restrict_max(query, _), do: query
-
defp restrict_actor(query, %{"actor_id" => actor_id}) do
from(activity in query, where: activity.actor == ^actor_id)
end
@@ -776,12 +763,7 @@ defp maybe_preload_objects(query, _) do
end
def fetch_activities_query(recipients, opts \\ %{}) do
- base_query =
- from(
- activity in Activity,
- limit: 20,
- order_by: [fragment("? desc nulls last", activity.id)]
- )
+ base_query = from(activity in Activity)
base_query
|> maybe_preload_objects(opts)
@@ -791,8 +773,6 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|> restrict_tag_all(opts)
|> restrict_since(opts)
|> restrict_local(opts)
- |> restrict_limit(opts)
- |> restrict_max(opts)
|> restrict_actor(opts)
|> restrict_type(opts)
|> restrict_favorited_by(opts)
@@ -808,14 +788,14 @@ def fetch_activities_query(recipients, opts \\ %{}) do
def fetch_activities(recipients, opts \\ %{}) do
fetch_activities_query(recipients, opts)
- |> Repo.all()
+ |> Pagination.fetch_paginated(opts)
|> Enum.reverse()
end
def fetch_activities_bounded(recipients_to, recipients_cc, opts \\ %{}) do
fetch_activities_query([], opts)
|> restrict_to_cc(recipients_to, recipients_cc)
- |> Repo.all()
+ |> Pagination.fetch_paginated(opts)
|> Enum.reverse()
end
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex
index 70a5b5c5d..c436715d5 100644
--- a/lib/pleroma/web/admin_api/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/admin_api_controller.ex
@@ -238,8 +238,13 @@ def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params)
!Pleroma.Config.get([:instance, :registrations_open]),
{:ok, invite_token} <- UserInviteToken.create_invite(),
email <-
- Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]),
- {:ok, _} <- Pleroma.Mailer.deliver(email) do
+ Pleroma.Emails.UserEmail.user_invitation_email(
+ user,
+ invite_token,
+ email,
+ params["name"]
+ ),
+ {:ok, _} <- Pleroma.Emails.Mailer.deliver(email) do
json_response(conn, :no_content, "")
end
end
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 7b9f0ea06..58a561a40 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -195,11 +195,10 @@ def format_input(text, "text/html", options) do
Formatting text to markdown.
"""
def format_input(text, "text/markdown", options) do
- options = Keyword.put(options, :mentions_escape, true)
-
text
+ |> Formatter.mentions_escape(options)
+ |> Earmark.as_html!()
|> Formatter.linkify(options)
- |> (fn {text, mentions, tags} -> {Earmark.as_html!(text), mentions, tags} end).()
|> Formatter.html_escape("text/html")
end
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index f3865b2f2..e0a090659 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Filter
alias Pleroma.Notification
alias Pleroma.Object
+ alias Pleroma.Pagination
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
alias Pleroma.Stats
@@ -202,15 +203,29 @@ def custom_emojis(conn, _params) do
defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
params =
conn.params
- |> Map.drop(["since_id", "max_id"])
+ |> Map.drop(["since_id", "max_id", "min_id"])
|> Map.merge(params)
last = List.last(activities)
- first = List.first(activities)
if last do
- min = last.id
- max = first.id
+ max_id = last.id
+
+ limit =
+ params
+ |> Map.get("limit", "20")
+ |> String.to_integer()
+
+ min_id =
+ if length(activities) <= limit do
+ activities
+ |> List.first()
+ |> Map.get(:id)
+ else
+ activities
+ |> Enum.at(limit * -1)
+ |> Map.get(:id)
+ end
{next_url, prev_url} =
if param do
@@ -219,13 +234,13 @@ defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
Pleroma.Web.Endpoint,
method,
param,
- Map.merge(params, %{max_id: min})
+ Map.merge(params, %{max_id: max_id})
),
mastodon_api_url(
Pleroma.Web.Endpoint,
method,
param,
- Map.merge(params, %{since_id: max})
+ Map.merge(params, %{min_id: min_id})
)
}
else
@@ -233,12 +248,12 @@ defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
mastodon_api_url(
Pleroma.Web.Endpoint,
method,
- Map.merge(params, %{max_id: min})
+ Map.merge(params, %{max_id: max_id})
),
mastodon_api_url(
Pleroma.Web.Endpoint,
method,
- Map.merge(params, %{since_id: max})
+ Map.merge(params, %{min_id: min_id})
)
}
end
@@ -314,7 +329,7 @@ def dm_timeline(%{assigns: %{user: user}} = conn, params) do
activities =
[user.ap_id]
|> ActivityPub.fetch_activities_query(params)
- |> Repo.all()
+ |> Pagination.fetch_paginated(params)
conn
|> add_link_headers(:dm_timeline, activities)
diff --git a/lib/pleroma/web/templates/layout/app.html.eex b/lib/pleroma/web/templates/layout/app.html.eex
index 8333bc921..3389c91cc 100644
--- a/lib/pleroma/web/templates/layout/app.html.eex
+++ b/lib/pleroma/web/templates/layout/app.html.eex
@@ -179,6 +179,17 @@
flex-basis: 50%;
}
}
+ .form-row {
+ display: flex;
+ }
+ .form-row > label {
+ text-align: left;
+ line-height: 47px;
+ flex: 1;
+ }
+ .form-row > input {
+ flex: 2;
+ }
diff --git a/lib/pleroma/web/templates/twitter_api/util/password_reset.html.eex b/lib/pleroma/web/templates/twitter_api/util/password_reset.html.eex
index 3c7960998..a3facf017 100644
--- a/lib/pleroma/web/templates/twitter_api/util/password_reset.html.eex
+++ b/lib/pleroma/web/templates/twitter_api/util/password_reset.html.eex
@@ -1,12 +1,13 @@
Password Reset for <%= @user.nickname %>
<%= form_for @conn, util_path(@conn, :password_reset), [as: "data"], fn f -> %>
-<%= label f, :password, "Password" %>
-<%= password_input f, :password %>
-
-
-<%= label f, :password_confirmation, "Confirmation" %>
-<%= password_input f, :password_confirmation %>
-
-<%= hidden_input f, :token, value: @token.token %>
-<%= submit "Reset" %>
+
+ <%= label f, :password, "Password" %>
+ <%= password_input f, :password %>
+
+
+ <%= label f, :password_confirmation, "Confirmation" %>
+ <%= password_input f, :password_confirmation %>
+
+ <%= hidden_input f, :token, value: @token.token %>
+ <%= submit "Reset" %>
<% end %>
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index 9e9a46cf1..d6ce0a7c6 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -4,10 +4,10 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
alias Pleroma.Activity
- alias Pleroma.Mailer
+ alias Pleroma.Emails.Mailer
+ alias Pleroma.Emails.UserEmail
alias Pleroma.Repo
alias Pleroma.User
- alias Pleroma.UserEmail
alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
diff --git a/mix.exs b/mix.exs
index 26a03b70b..9531b230a 100644
--- a/mix.exs
+++ b/mix.exs
@@ -22,7 +22,7 @@ def project do
homepage_url: "https://pleroma.social/",
docs: [
logo: "priv/static/static/logo.png",
- extras: ["README.md" | Path.wildcard("docs/**/*.md")],
+ extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"),
groups_for_extras: [
"Installation manuals": Path.wildcard("docs/installation/*.md"),
Configuration: Path.wildcard("docs/config/*.md"),
@@ -101,7 +101,7 @@ defp deps do
{:ueberauth, "~> 0.4"},
{:auto_linker,
git: "https://git.pleroma.social/pleroma/auto_linker.git",
- ref: "479dd343f4e563ff91215c8275f3b5c67e032850"},
+ ref: "90613b4bae875a3610c275b7056b61ffdd53210d"},
{:pleroma_job_queue, "~> 0.2.0"},
{:telemetry, "~> 0.3"},
{:prometheus_ex, "~> 3.0"},
diff --git a/mix.lock b/mix.lock
index bb40ebd48..e13fdcbd4 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,6 +1,6 @@
%{
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"},
- "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "479dd343f4e563ff91215c8275f3b5c67e032850", [ref: "479dd343f4e563ff91215c8275f3b5c67e032850"]},
+ "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "90613b4bae875a3610c275b7056b61ffdd53210d", [ref: "90613b4bae875a3610c275b7056b61ffdd53210d"]},
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"cachex": {:hex, :cachex, "3.0.2", "1351caa4e26e29f7d7ec1d29b53d6013f0447630bbf382b4fb5d5bad0209f203", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"},
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index d44392c9d..6d89a0919 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -318,7 +318,7 @@ test "sends invitation and returns 204", %{conn: conn, user: user} do
refute token_record.used
Swoosh.TestAssertions.assert_email_sent(
- Pleroma.UserEmail.user_invitation_email(
+ Pleroma.Emails.UserEmail.user_invitation_email(
user,
token_record,
recipient_email,
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index a906c6082..292cd46b8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1473,7 +1473,7 @@ test "getting followers, pagination", %{conn: conn} do
assert id2 == follower2.id
assert [link_header] = get_resp_header(res_conn, "link")
- assert link_header =~ ~r/since_id=#{follower2.id}/
+ assert link_header =~ ~r/min_id=#{follower2.id}/
assert link_header =~ ~r/max_id=#{follower2.id}/
end
@@ -1552,7 +1552,7 @@ test "getting following, pagination", %{conn: conn} do
assert id2 == following2.id
assert [link_header] = get_resp_header(res_conn, "link")
- assert link_header =~ ~r/since_id=#{following2.id}/
+ assert link_header =~ ~r/min_id=#{following2.id}/
assert link_header =~ ~r/max_id=#{following2.id}/
end
@@ -2382,7 +2382,7 @@ test "preserves parameters in link headers", %{conn: conn} do
assert [link_header] = get_resp_header(conn, "link")
assert link_header =~ ~r/media_only=true/
- assert link_header =~ ~r/since_id=#{notification2.id}/
+ assert link_header =~ ~r/min_id=#{notification2.id}/
assert link_header =~ ~r/max_id=#{notification1.id}/
end
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 72b7ea85e..b3e01e943 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1064,7 +1064,7 @@ test "it sends an email to user", %{user: user} do
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
Swoosh.TestAssertions.assert_email_sent(
- Pleroma.UserEmail.password_reset_email(user, token_record.token)
+ Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
)
end
end
@@ -1163,7 +1163,9 @@ test "it sends confirmation email", %{conn: conn, user: user} do
|> assign(:user, user)
|> post("/api/account/resend_confirmation_email?email=#{user.email}")
- Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+ Swoosh.TestAssertions.assert_email_sent(
+ Pleroma.Emails.UserEmail.account_confirmation_email(user)
+ )
end
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index a4540e651..6d43bd13a 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -325,7 +325,9 @@ test "it sends confirmation email if :account_activation_required is specified i
assert user.info.confirmation_pending
- Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+ Swoosh.TestAssertions.assert_email_sent(
+ Pleroma.Emails.UserEmail.account_confirmation_email(user)
+ )
end
test "it registers a new user and parses mentions in the bio" do