aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex S <alex.strizhakov@gmail.com>2019-04-13 12:24:38 +0700
committerAlex S <alex.strizhakov@gmail.com>2019-04-13 12:24:38 +0700
commitc349573791bfaca6e8c8c86c519c23397b088967 (patch)
treed98225031c8ad1b3efe7c2917fd911d369953ca7 /lib
parenta64eb2b3893cee61f50d89b6ad4d273031ef0ea9 (diff)
parent334b2d78dc068f65fabf5b11aaa737dfd742d2f4 (diff)
downloadpleroma-c349573791bfaca6e8c8c86c519c23397b088967.tar.gz
Merge develop to 788-separate-email-addresses
Merge conflicts: test/web/twitter_api/twitter_api_test.exs test/web/twitter_api/twitter_api_controller_test.exs test/web/admin_api/admin_api_controller_test.exs
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/emails/admin_email.ex2
-rw-r--r--lib/pleroma/emails/mailer.ex2
-rw-r--r--lib/pleroma/emails/user_email.ex2
-rw-r--r--lib/pleroma/formatter.ex42
-rw-r--r--lib/pleroma/notification.ex11
-rw-r--r--lib/pleroma/pagination.ex6
-rw-r--r--lib/pleroma/user.ex4
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex34
-rw-r--r--lib/pleroma/web/admin_api/admin_api_controller.ex9
-rw-r--r--lib/pleroma/web/common_api/utils.ex5
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex38
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex6
-rw-r--r--lib/pleroma/web/rel_me.ex3
-rw-r--r--lib/pleroma/web/rich_media/parser.ex3
-rw-r--r--lib/pleroma/web/router.ex1
-rw-r--r--lib/pleroma/web/templates/layout/app.html.eex11
-rw-r--r--lib/pleroma/web/templates/twitter_api/util/password_reset.html.eex19
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex4
18 files changed, 130 insertions, 72 deletions
diff --git a/lib/pleroma/emails/admin_email.ex b/lib/pleroma/emails/admin_email.ex
index e730410c5..df0f72f96 100644
--- a/lib/pleroma/emails/admin_email.ex
+++ b/lib/pleroma/emails/admin_email.ex
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.AdminEmail do
+defmodule Pleroma.Emails.AdminEmail do
@moduledoc "Admin emails"
import Swoosh.Email
diff --git a/lib/pleroma/emails/mailer.ex b/lib/pleroma/emails/mailer.ex
index b384e6fec..53f5a661c 100644
--- a/lib/pleroma/emails/mailer.ex
+++ b/lib/pleroma/emails/mailer.ex
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Mailer do
+defmodule Pleroma.Emails.Mailer do
use Swoosh.Mailer, otp_app: :pleroma
def deliver_async(email, config \\ []) do
diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex
index ca0772f57..8502a0d0c 100644
--- a/lib/pleroma/emails/user_email.ex
+++ b/lib/pleroma/emails/user_email.ex
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.UserEmail do
+defmodule Pleroma.Emails.UserEmail do
@moduledoc "User emails"
import Swoosh.Email
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 8ea9dbd38..dab8910c1 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -9,20 +9,31 @@ defmodule Pleroma.Formatter do
alias Pleroma.Web.MediaProxy
@safe_mention_regex ~r/^(\s*(?<mentions>@.+?\s+)+)(?<rest>.*)/
+ @link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
- @link_regex ~r{((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+}ui
- # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
@auto_linker_config hashtag: true,
hashtag_handler: &Pleroma.Formatter.hashtag_handler/4,
mention: true,
mention_handler: &Pleroma.Formatter.mention_handler/4
+ def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
+ case User.get_cached_by_nickname(nickname) do
+ %User{} ->
+ # escape markdown characters with `\\`
+ # (we don't want something like @user__name to be parsed by markdown)
+ String.replace(mention, @markdown_characters_regex, "\\\\\\1")
+
+ _ ->
+ buffer
+ end
+ end
+
def mention_handler("@" <> nickname, buffer, opts, acc) do
case User.get_cached_by_nickname(nickname) do
%User{id: id} = user ->
ap_id = get_ap_id(user)
- nickname_text = get_nickname_text(nickname, opts) |> maybe_escape(opts)
+ nickname_text = get_nickname_text(nickname, opts)
link =
"<span class='h-card'><a data-user='#{id}' class='u-url mention' href='#{ap_id}'>@<span>#{
@@ -70,6 +81,25 @@ defmodule Pleroma.Formatter 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 @@ defmodule Pleroma.Formatter do
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/notification.ex b/lib/pleroma/notification.ex
index 15789907a..b357d5399 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -98,6 +98,14 @@ defmodule Pleroma.Notification do
|> Repo.delete_all()
end
+ def destroy_multiple(%{id: user_id} = _user, ids) do
+ from(n in Notification,
+ where: n.id in ^ids,
+ where: n.user_id == ^user_id
+ )
+ |> Repo.delete_all()
+ end
+
def dismiss(%{id: user_id} = _user, id) do
notification = Repo.get(Notification, id)
@@ -173,8 +181,7 @@ defmodule Pleroma.Notification do
def skip?(:muted, activity, user) do
actor = activity.data["actor"]
- User.mutes?(user, %{ap_id: actor}) or
- CommonAPI.thread_muted?(user, activity)
+ User.mutes?(user, %{ap_id: actor}) or CommonAPI.thread_muted?(user, activity)
end
def skip?(
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 @@ defmodule Pleroma.Pagination 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 @@ defmodule Pleroma.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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
: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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
q
|> restrict_unlisted()
- |> Repo.all()
+ |> Pagination.fetch_paginated(opts)
|> Enum.reverse()
end
@@ -636,26 +637,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
!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 @@ defmodule Pleroma.Web.CommonAPI.Utils 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 ed082abdf..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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
activities =
[user.ap_id]
|> ActivityPub.fetch_activities_query(params)
- |> Repo.all()
+ |> Pagination.fetch_paginated(params)
conn
|> add_link_headers(:dm_timeline, activities)
@@ -612,6 +627,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
+ def destroy_multiple(%{assigns: %{user: user}} = conn, %{"ids" => ids} = _params) do
+ Notification.destroy_multiple(user, ids)
+ json(conn, %{})
+ end
+
def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
id = List.wrap(id)
q = from(u in User, where: u.id in ^id)
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index d4a8e4fff..bdc33186e 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -301,8 +301,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do
- _id = activity.data["object"]["inReplyTo"]
- replied_to_activities[activity.data["object"]["inReplyTo"]]
+ with nil <- replied_to_activities[activity.data["object"]["inReplyTo"]] do
+ # If user didn't participate in the thread
+ Activity.get_in_reply_to_activity(activity)
+ end
end
def get_reply_to(%{data: %{"object" => object}}, _) do
diff --git a/lib/pleroma/web/rel_me.ex b/lib/pleroma/web/rel_me.ex
index eaca41132..26eb614a6 100644
--- a/lib/pleroma/web/rel_me.ex
+++ b/lib/pleroma/web/rel_me.ex
@@ -6,7 +6,8 @@ defmodule Pleroma.Web.RelMe do
@hackney_options [
pool: :media,
recv_timeout: 2_000,
- max_body: 2_000_000
+ max_body: 2_000_000,
+ with_body: true
]
if Mix.env() == :test do
diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex
index 4bd271d8e..62e8fa610 100644
--- a/lib/pleroma/web/rich_media/parser.ex
+++ b/lib/pleroma/web/rich_media/parser.ex
@@ -12,7 +12,8 @@ defmodule Pleroma.Web.RichMedia.Parser do
@hackney_options [
pool: :media,
recv_timeout: 2_000,
- max_body: 2_000_000
+ max_body: 2_000_000,
+ with_body: true
]
def parse(nil), do: {:error, "No URL provided"}
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 172f337db..a809347be 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -261,6 +261,7 @@ defmodule Pleroma.Web.Router do
post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
get("/notifications", MastodonAPIController, :notifications)
get("/notifications/:id", MastodonAPIController, :get_notification)
+ delete("/notifications/destroy_multiple", MastodonAPIController, :destroy_multiple)
get("/scheduled_statuses", MastodonAPIController, :scheduled_statuses)
get("/scheduled_statuses/:id", MastodonAPIController, :show_scheduled_status)
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;
+ }
</style>
</head>
<body>
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 @@
<h2>Password Reset for <%= @user.nickname %></h2>
<%= form_for @conn, util_path(@conn, :password_reset), [as: "data"], fn f -> %>
-<%= label f, :password, "Password" %>
-<%= password_input f, :password %>
-<br>
-
-<%= label f, :password_confirmation, "Confirmation" %>
-<%= password_input f, :password_confirmation %>
-<br>
-<%= hidden_input f, :token, value: @token.token %>
-<%= submit "Reset" %>
+ <div class="form-row">
+ <%= label f, :password, "Password" %>
+ <%= password_input f, :password %>
+ </div>
+ <div class="form-row">
+ <%= label f, :password_confirmation, "Confirmation" %>
+ <%= password_input f, :password_confirmation %>
+ </div>
+ <%= 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