aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex2
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub_controller.ex2
-rw-r--r--lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex4
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex82
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex2
-rw-r--r--lib/pleroma/web/admin_api/admin_api_controller.ex55
-rw-r--r--lib/pleroma/web/common_api/utils.ex4
-rw-r--r--lib/pleroma/web/federator/federator.ex5
-rw-r--r--lib/pleroma/web/federator/retry_queue.ex11
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex15
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_socket.ex19
-rw-r--r--lib/pleroma/web/mastodon_api/views/mastodon_view.ex1
-rw-r--r--lib/pleroma/web/mastodon_api/views/push_subscription_view.ex1
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex111
-rw-r--r--lib/pleroma/web/media_proxy/controller.ex8
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex2
-rw-r--r--lib/pleroma/web/ostatus/ostatus.ex21
-rw-r--r--lib/pleroma/web/ostatus/ostatus_controller.ex4
-rw-r--r--lib/pleroma/web/router.ex2
-rw-r--r--lib/pleroma/web/streamer.ex2
-rw-r--r--lib/pleroma/web/twitter_api/controllers/util_controller.ex3
-rw-r--r--lib/pleroma/web/twitter_api/representers/activity_representer.ex6
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex13
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex8
-rw-r--r--lib/pleroma/web/xml/xml.ex8
25 files changed, 186 insertions, 205 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index bf81d8039..31455343c 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -799,7 +799,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
# guard
- def entire_thread_visible_for_user?(nil, user), do: false
+ def entire_thread_visible_for_user?(nil, _user), do: false
# child
def entire_thread_visible_for_user?(
diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
index 3570a75cb..0317f3c8c 100644
--- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
@@ -141,7 +141,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
json(conn, "error")
end
- def relay(conn, params) do
+ def relay(conn, _params) do
with %User{} = user <- Relay.get_actor(),
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
conn
diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex
index c8c74ede6..6fa48454a 100644
--- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex
+++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex
@@ -5,7 +5,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
def filter_by_summary(
- %{"summary" => parent_summary} = parent,
+ %{"summary" => parent_summary} = _parent,
%{"summary" => child_summary} = child
)
when not is_nil(child_summary) and byte_size(child_summary) > 0 and
@@ -19,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
end
end
- def filter_by_summary(parent, child), do: child
+ def filter_by_summary(_parent, child), do: child
def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
child = object["object"]
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 17b063609..e6af4b211 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -37,9 +37,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
@doc """
Checks that an imported AP object's actor matches the domain it came from.
"""
- def contain_origin(id, %{"actor" => nil}), do: :error
+ def contain_origin(_id, %{"actor" => nil}), do: :error
- def contain_origin(id, %{"actor" => actor} = params) do
+ def contain_origin(id, %{"actor" => _actor} = params) do
id_uri = URI.parse(id)
actor_uri = URI.parse(get_actor(params))
@@ -50,9 +50,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
- def contain_origin_from_id(id, %{"id" => nil}), do: :error
+ def contain_origin_from_id(_id, %{"id" => nil}), do: :error
- def contain_origin_from_id(id, %{"id" => other_id} = params) do
+ def contain_origin_from_id(id, %{"id" => other_id} = _params) do
id_uri = URI.parse(id)
other_uri = URI.parse(other_id)
@@ -266,6 +266,32 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def fix_content_map(object), do: object
+ defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
+ with true <- id =~ "follows",
+ %User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
+ %Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do
+ {:ok, activity}
+ else
+ _ -> {:error, nil}
+ end
+ end
+
+ defp mastodon_follow_hack(_, _), do: {:error, nil}
+
+ defp get_follow_activity(follow_object, followed) do
+ with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object),
+ {_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do
+ {:ok, activity}
+ else
+ # Can't find the activity. This might a Mastodon 2.3 "Accept"
+ {:activity, nil} ->
+ mastodon_follow_hack(follow_object, followed)
+
+ _ ->
+ {:error, nil}
+ end
+ end
+
# disallow objects with bogus IDs
def handle_incoming(%{"id" => nil}), do: :error
def handle_incoming(%{"id" => ""}), do: :error
@@ -331,34 +357,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
- defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
- with true <- id =~ "follows",
- %User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
- %Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do
- {:ok, activity}
- else
- _ -> {:error, nil}
- end
- end
-
- defp mastodon_follow_hack(_), do: {:error, nil}
-
- defp get_follow_activity(follow_object, followed) do
- with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object),
- {_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do
- {:ok, activity}
- else
- # Can't find the activity. This might a Mastodon 2.3 "Accept"
- {:activity, nil} ->
- mastodon_follow_hack(follow_object, followed)
-
- _ ->
- {:error, nil}
- end
- end
-
def handle_incoming(
- %{"type" => "Accept", "object" => follow_object, "actor" => actor, "id" => id} = data
+ %{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data
) do
with actor <- get_actor(data),
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
@@ -374,7 +374,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
local: false
}) do
if not User.following?(follower, followed) do
- {:ok, follower} = User.follow(follower, followed)
+ {:ok, _follower} = User.follow(follower, followed)
end
{:ok, activity}
@@ -384,7 +384,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def handle_incoming(
- %{"type" => "Reject", "object" => follow_object, "actor" => actor, "id" => id} = data
+ %{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data
) do
with actor <- get_actor(data),
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
@@ -408,7 +408,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def handle_incoming(
- %{"type" => "Like", "object" => object_id, "actor" => actor, "id" => id} = data
+ %{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data
) do
with actor <- get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
@@ -421,7 +421,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def handle_incoming(
- %{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data
+ %{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data
) do
with actor <- get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
@@ -492,7 +492,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{
"type" => "Undo",
"object" => %{"type" => "Announce", "object" => object_id},
- "actor" => actor,
+ "actor" => _actor,
"id" => id
} = data
) do
@@ -520,7 +520,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
User.unfollow(follower, followed)
{:ok, activity}
else
- e -> :error
+ _e -> :error
end
end
@@ -539,12 +539,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
User.unblock(blocker, blocked)
{:ok, activity}
else
- e -> :error
+ _e -> :error
end
end
def handle_incoming(
- %{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = data
+ %{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = _data
) do
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
%User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
@@ -554,7 +554,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
User.block(blocker, blocked)
{:ok, activity}
else
- e -> :error
+ _e -> :error
end
end
@@ -562,7 +562,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{
"type" => "Undo",
"object" => %{"type" => "Like", "object" => object_id},
- "actor" => actor,
+ "actor" => _actor,
"id" => id
} = data
) do
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 549148989..074622f2b 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -292,7 +292,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
"""
def make_follow_data(
%User{ap_id: follower_id},
- %User{ap_id: followed_id} = followed,
+ %User{ap_id: followed_id} = _followed,
activity_id
) do
data = %{
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex
index 0bd85e0b6..06c3c7c81 100644
--- a/lib/pleroma/web/admin_api/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/admin_api_controller.ex
@@ -63,13 +63,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
info_cng = User.Info.admin_api_update(user.info, info)
cng =
- Ecto.Changeset.change(user)
+ user
+ |> Ecto.Changeset.change()
|> Ecto.Changeset.put_embed(:info, info_cng)
- {:ok, user} = User.update_and_set_cache(cng)
+ {:ok, _user} = User.update_and_set_cache(cng)
+ json(conn, info)
+ end
+
+ def right_add(conn, _) do
conn
- |> json(info)
+ |> put_status(404)
+ |> json(%{error: "No such permission_group"})
end
def right_get(conn, %{"nickname" => nickname}) do
@@ -82,12 +88,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
})
end
- def right_add(conn, _) do
- conn
- |> put_status(404)
- |> json(%{error: "No such permission_group"})
- end
-
def right_delete(
%{assigns: %{user: %User{:nickname => admin_nickname}}} = conn,
%{
@@ -113,10 +113,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
Ecto.Changeset.change(user)
|> Ecto.Changeset.put_embed(:info, info_cng)
- {:ok, user} = User.update_and_set_cache(cng)
+ {:ok, _user} = User.update_and_set_cache(cng)
- conn
- |> json(info)
+ json(conn, info)
end
end
@@ -127,32 +126,28 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def relay_follow(conn, %{"relay_url" => target}) do
- {status, message} = Relay.follow(target)
-
- if status == :ok do
- conn
- |> json(target)
+ with {:ok, _message} <- Relay.follow(target) do
+ json(conn, target)
else
- conn
- |> put_status(500)
- |> json(target)
+ _ ->
+ conn
+ |> put_status(500)
+ |> json(target)
end
end
def relay_unfollow(conn, %{"relay_url" => target}) do
- {status, message} = Relay.unfollow(target)
-
- if status == :ok do
- conn
- |> json(target)
+ with {:ok, _message} <- Relay.unfollow(target) do
+ json(conn, target)
else
- conn
- |> put_status(500)
- |> json(target)
+ _ ->
+ conn
+ |> put_status(500)
+ |> json(target)
end
end
- @shortdoc "Get a account registeration invite token (base64 string)"
+ @doc "Get a account registeration invite token (base64 string)"
def get_invite_token(conn, _params) do
{:ok, token} = Pleroma.UserInviteToken.create_token()
@@ -160,7 +155,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|> json(token.token)
end
- @shortdoc "Get a password reset token (base64 string) for given nickname"
+ @doc "Get a password reset token (base64 string) for given nickname"
def get_password_reset(conn, %{"nickname" => nickname}) do
(%User{local: true} = user) = User.get_by_nickname(nickname)
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 728f24c7e..8f2625cef 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -122,7 +122,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|> Formatter.finalize()
end
- def format_input(text, mentions, tags, "text/html") do
+ def format_input(text, mentions, _tags, "text/html") do
text
|> Formatter.html_escape("text/html")
|> String.replace(~r/\r?\n/, "<br>")
@@ -236,7 +236,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end
end
- def emoji_from_profile(%{info: info} = user) do
+ def emoji_from_profile(%{info: _info} = user) do
(Formatter.get_emoji(user.bio) ++ Formatter.get_emoji(user.name))
|> Enum.map(fn {shortcode, url} ->
%{
diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex
index ac3d7c132..a9c7aecd5 100644
--- a/lib/pleroma/web/federator/federator.ex
+++ b/lib/pleroma/web/federator/federator.ex
@@ -13,7 +13,6 @@ defmodule Pleroma.Web.Federator do
@websub Application.get_env(:pleroma, :websub)
@ostatus Application.get_env(:pleroma, :ostatus)
- @httpoison Application.get_env(:pleroma, :httpoison)
@max_jobs 20
def init(args) do
@@ -134,7 +133,7 @@ defmodule Pleroma.Web.Federator do
def handle(
:publish_single_websub,
- %{xml: xml, topic: topic, callback: callback, secret: secret} = params
+ %{xml: _xml, topic: _topic, callback: _callback, secret: _secret} = params
) do
case Websub.publish_one(params) do
{:ok, _} ->
@@ -151,7 +150,7 @@ defmodule Pleroma.Web.Federator do
end
if Mix.env() == :test do
- def enqueue(type, payload, priority \\ 1) do
+ def enqueue(type, payload, _priority \\ 1) do
if Pleroma.Config.get([:instance, :federating]) do
handle(type, payload)
end
diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex
index 13df40c80..510b4315d 100644
--- a/lib/pleroma/web/federator/retry_queue.ex
+++ b/lib/pleroma/web/federator/retry_queue.ex
@@ -1,13 +1,8 @@
defmodule Pleroma.Web.Federator.RetryQueue do
use GenServer
- alias Pleroma.Web.{WebFinger, Websub}
- alias Pleroma.Web.ActivityPub.ActivityPub
+
require Logger
- @websub Application.get_env(:pleroma, :websub)
- @ostatus Application.get_env(:pleroma, :websub)
- @httpoison Application.get_env(:pleroma, :websub)
- @instance Application.get_env(:pleroma, :websub)
# initial timeout, 5 min
@initial_timeout 30_000
@max_retries 5
@@ -46,7 +41,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do
Process.send_after(
__MODULE__,
{:send, data, transport, retries},
- growth_function(retries)
+ timeout
)
{:noreply, state}
@@ -62,7 +57,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do
{:ok, _} ->
{:noreply, %{state | delivered: delivery_count + 1}}
- {:error, reason} ->
+ {:error, _reason} ->
enqueue(data, transport, retries)
{:noreply, state}
end
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 2d7b1a00c..5c8602322 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -437,10 +437,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
# Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array.
- def relationships(%{assigns: %{user: user}} = conn, _) do
- conn
- |> json([])
- end
+ def relationships(%{assigns: %{user: _user}} = conn, _), do: json(conn, [])
def update_media(%{assigns: %{user: user}} = conn, data) do
with %Object{} = object <- Repo.get(Object, data["id"]),
@@ -850,7 +847,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def list_timeline(%{assigns: %{user: user}} = conn, %{"list_id" => id} = params) do
- with %Pleroma.List{title: title, following: following} <- Pleroma.List.get(id, user) do
+ with %Pleroma.List{title: _title, following: following} <- Pleroma.List.get(id, user) do
params =
params
|> Map.put("type", "Create")
@@ -983,13 +980,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
with changeset <- User.update_changeset(user),
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
- {:ok, user} <- User.update_and_set_cache(changeset) do
- conn
- |> json(%{})
+ {:ok, _user} <- User.update_and_set_cache(changeset) do
+ json(conn, %{})
else
e ->
- conn
- |> json(%{error: inspect(e)})
+ json(conn, %{error: inspect(e)})
end
end
diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex
index f3c13d1aa..755ac5730 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex
@@ -5,12 +5,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
alias Pleroma.{User, Repo}
transport(
- :streaming,
+ :websocket,
Phoenix.Transports.WebSocket.Raw,
# We never receive data.
timeout: :infinity
)
+ @spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error
def connect(%{"access_token" => token} = params, socket) do
with %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
%User{} = user <- Repo.get(User, user_id),
@@ -52,16 +53,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
_ -> stream
end
- with socket =
- socket
- |> assign(:topic, topic) do
- Pleroma.Web.Streamer.add_socket(topic, socket)
- {:ok, socket}
- else
- _e -> :error
- end
+ socket =
+ socket
+ |> assign(:topic, topic)
+
+ Pleroma.Web.Streamer.add_socket(topic, socket)
+ {:ok, socket}
end
+ def connect(_params, _socket), do: :error
+
def id(_), do: nil
def handle(:text, message, _state) do
diff --git a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex
index 370fad374..1fd05d9f1 100644
--- a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex
@@ -1,5 +1,4 @@
defmodule Pleroma.Web.MastodonAPI.MastodonView do
use Pleroma.Web, :view
import Phoenix.HTML
- import Phoenix.HTML.Form
end
diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex
index 68bb45494..c8b95d14c 100644
--- a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex
@@ -1,6 +1,5 @@
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do
use Pleroma.Web, :view
- alias Pleroma.Web.MastodonAPI.PushSubscriptionView
def render("push_subscription.json", %{subscription: subscription}) do
%{
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 2d9a915f0..c3c735d5d 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -1,18 +1,21 @@
defmodule Pleroma.Web.MastodonAPI.StatusView do
use Pleroma.Web, :view
- alias Pleroma.Web.MastodonAPI.{AccountView, StatusView}
- alias Pleroma.{User, Activity}
+
+ alias Pleroma.Activity
+ alias Pleroma.HTML
+ alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
- alias Pleroma.Repo
- alias Pleroma.HTML
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
# TODO: Add cached version.
defp get_replied_to_activities(activities) do
activities
|> Enum.map(fn
- %{data: %{"type" => "Create", "object" => %{"inReplyTo" => inReplyTo}}} ->
- inReplyTo != "" && inReplyTo
+ %{data: %{"type" => "Create", "object" => %{"inReplyTo" => in_reply_to}}} ->
+ in_reply_to != "" && in_reply_to
_ ->
nil
@@ -28,8 +31,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render("index.json", opts) do
replied_to_activities = get_replied_to_activities(opts.activities)
- render_many(
- opts.activities,
+ opts.activities
+ |> render_many(
StatusView,
"status.json",
Map.put(opts, :replied_to_activities, replied_to_activities)
@@ -72,9 +75,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
sensitive: false,
spoiler_text: "",
visibility: "public",
- media_attachments: [],
+ media_attachments: reblogged[:media_attachments] || [],
mentions: mentions,
- tags: [],
+ tags: reblogged[:tags] || [],
application: %{
name: "Web",
website: nil
@@ -111,20 +114,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
reply_to = get_reply_to(activity, opts)
reply_to_user = reply_to && User.get_cached_by_ap_id(reply_to.data["actor"])
- emojis =
- (activity.data["object"]["emoji"] || [])
- |> Enum.map(fn {name, url} ->
- name = HTML.strip_tags(name)
-
- url =
- HTML.strip_tags(url)
- |> MediaProxy.url()
-
- %{shortcode: name, url: url, static_url: url, visible_in_picker: false}
- end)
-
content =
- render_content(object)
+ object
+ |> render_content()
|> HTML.filter_tags(User.html_filter_policy(opts[:for]))
%{
@@ -140,22 +132,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
reblogs_count: announcement_count,
replies_count: 0,
favourites_count: like_count,
- reblogged: !!repeated,
- favourited: !!favorited,
+ reblogged: present?(repeated),
+ favourited: present?(favorited),
muted: false,
sensitive: sensitive,
spoiler_text: object["summary"] || "",
visibility: get_visibility(object),
media_attachments: attachments |> Enum.take(4),
mentions: mentions,
- # fix,
- tags: [],
+ tags: tags,
application: %{
name: "Web",
website: nil
},
language: nil,
- emojis: emojis
+ emojis: build_emojis(activity.data["object"]["emoji"])
}
end
@@ -224,30 +215,56 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
def render_content(%{"type" => "Video"} = object) do
- name = object["name"]
-
- content =
- if !!name and name != "" do
- "<p><a href=\"#{object["id"]}\">#{name}</a></p>#{object["content"]}"
- else
- object["content"] || ""
- end
+ with name when not is_nil(name) and name != "" <- object["name"] do
+ "<p><a href=\"#{object["id"]}\">#{name}</a></p>#{object["content"]}"
+ else
+ _ -> object["content"] || ""
+ end
+ end
- content
+ def render_content(%{"type" => object_type} = object)
+ when object_type in ["Article", "Page"] do
+ with summary when not is_nil(summary) and summary != "" <- object["name"],
+ url when is_bitstring(url) <- object["url"] do
+ "<p><a href=\"#{url}\">#{summary}</a></p>#{object["content"]}"
+ else
+ _ -> object["content"] || ""
+ end
end
- def render_content(%{"type" => object_type} = object) when object_type in ["Article", "Page"] do
- summary = object["name"]
+ def render_content(object), do: object["content"] || ""
- content =
- if !!summary and summary != "" and is_bitstring(object["url"]) do
- "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
- else
- object["content"] || ""
- end
+ @doc """
+ Builds list emojis.
+
+ Arguments: `nil` or list tuple of name and url.
+
+ Returns list emojis.
- content
+ ## Examples
+
+ iex> Pleroma.Web.MastodonAPI.StatusView.build_emojis([{"2hu", "corndog.png"}])
+ [%{shortcode: "2hu", static_url: "corndog.png", url: "corndog.png", visible_in_picker: false}]
+
+ """
+ @spec build_emojis(nil | list(tuple())) :: list(map())
+ def build_emojis(nil), do: []
+
+ def build_emojis(emojis) do
+ emojis
+ |> Enum.map(fn {name, url} ->
+ name = HTML.strip_tags(name)
+
+ url =
+ url
+ |> HTML.strip_tags()
+ |> MediaProxy.url()
+
+ %{shortcode: name, url: url, static_url: url, visible_in_picker: false}
+ end)
end
- def render_content(object), do: object["content"] || ""
+ defp present?(nil), do: false
+ defp present?(false), do: false
+ defp present?(_), do: true
end
diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex
index f496fc936..63140feb9 100644
--- a/lib/pleroma/web/media_proxy/controller.ex
+++ b/lib/pleroma/web/media_proxy/controller.ex
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
with config <- Pleroma.Config.get([:media_proxy], []),
true <- Keyword.get(config, :enabled, false),
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
- filename <- Path.basename(URI.parse(url).path),
:ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
else
@@ -31,9 +30,10 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
path = URI.decode(path)
- cond do
- has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename}
- true -> :ok
+ if has_filename && filename && Path.basename(path) != filename do
+ {:wrong_filename, filename}
+ else
+ :ok
end
end
end
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index d03c8b05a..20c2e799b 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -121,7 +121,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
def token_exchange(
conn,
- %{"grant_type" => "password", "name" => name, "password" => password} = params
+ %{"grant_type" => "password", "name" => name, "password" => _password} = params
) do
params =
params
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index 53d71440e..c6440c20e 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -375,19 +375,14 @@ defmodule Pleroma.Web.OStatus do
end
def fetch_activity_from_url(url) do
- try do
- with {:ok, activities} when length(activities) > 0 <- fetch_activity_from_atom_url(url) do
- {:ok, activities}
- else
- _e ->
- with {:ok, activities} <- fetch_activity_from_html_url(url) do
- {:ok, activities}
- end
- end
- rescue
- e ->
- Logger.debug("Couldn't get #{url}: #{inspect(e)}")
- {:error, "Couldn't get #{url}: #{inspect(e)}"}
+ with {:ok, [_ | _] = activities} <- fetch_activity_from_atom_url(url) do
+ {:ok, activities}
+ else
+ _e -> fetch_activity_from_html_url(url)
end
+ rescue
+ e ->
+ Logger.debug("Couldn't get #{url}: #{inspect(e)}")
+ {:error, "Couldn't get #{url}: #{inspect(e)}"}
end
end
diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex
index af6e22c2b..9dfcf0f95 100644
--- a/lib/pleroma/web/ostatus/ostatus_controller.ex
+++ b/lib/pleroma/web/ostatus/ostatus_controller.ex
@@ -157,7 +157,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
conn,
"activity+json",
%Activity{data: %{"type" => "Create"}} = activity,
- user
+ _user
) do
object = Object.normalize(activity.data["object"])
@@ -166,7 +166,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|> json(ObjectView.render("object.json", %{object: object}))
end
- defp represent_activity(conn, "activity+json", _, _) do
+ defp represent_activity(_conn, "activity+json", _, _) do
{:error, :not_found}
end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 4d24d4c1c..9c06fac4f 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -1,8 +1,6 @@
defmodule Pleroma.Web.Router do
use Pleroma.Web, :router
- alias Pleroma.{Repo, User, Web.Router}
-
pipeline :api do
plug(:accepts, ["json"])
plug(:fetch_session)
diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex
index 99b8b7063..29c44e9d5 100644
--- a/lib/pleroma/web/streamer.ex
+++ b/lib/pleroma/web/streamer.ex
@@ -61,8 +61,6 @@ defmodule Pleroma.Web.Streamer do
end
def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do
- author = User.get_cached_by_ap_id(item.data["actor"])
-
# filter the recipient list if the activity is not public, see #270.
recipient_lists =
case ActivityPub.is_public?(item) do
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index 092779010..0ed519ea6 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -6,9 +6,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
alias Pleroma.Web.WebFinger
alias Pleroma.Web.CommonAPI
alias Comeonin.Pbkdf2
- alias Pleroma.{Formatter, Emoji}
alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.{Repo, PasswordResetToken, User}
+ alias Pleroma.{Repo, PasswordResetToken, User, Emoji}
def show_password_reset(conn, %{"token" => token}) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
index fbd33f07e..2808192b0 100644
--- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex
+++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex
@@ -141,7 +141,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
end
def to_map(
- %Activity{data: %{"object" => %{"content" => content} = object}} = activity,
+ %Activity{data: %{"object" => %{"content" => _content} = object}} = activity,
%{user: user} = opts
) do
created_at = object["published"] |> Utils.date_to_asctime()
@@ -165,7 +165,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
- {summary, content} = ActivityView.render_content(object)
+ {_summary, content} = ActivityView.render_content(object)
html =
HTML.filter_tags(content, User.html_filter_policy(opts[:for]))
@@ -173,7 +173,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
video =
if object["type"] == "Video" do
- vid = [object]
+ [object]
else
[]
end
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index 9c485d965..79ea48d86 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -2,18 +2,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
alias Pleroma.{UserInviteToken, User, Activity, Repo, Object}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
- alias Pleroma.Web.{OStatus, CommonAPI}
- alias Pleroma.Web.MediaProxy
+ alias Pleroma.Web.CommonAPI
import Ecto.Query
- @httpoison Application.get_env(:pleroma, :httpoison)
-
def create_status(%User{} = user, %{"status" => _} = data) do
CommonAPI.post(user, data)
end
def delete(%User{} = user, id) do
- with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id),
+ with %Activity{data: %{"type" => _type}} <- Repo.get(Activity, id),
{:ok, activity} <- CommonAPI.delete(id, user) do
{:ok, activity}
end
@@ -37,7 +34,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
def unfollow(%User{} = follower, params) do
with {:ok, %User{} = unfollowed} <- get_user(params),
- {:ok, follower, follow_activity} <- User.unfollow(follower, unfollowed),
+ {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),
{:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do
{:ok, follower, unfollowed}
else
@@ -244,10 +241,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
_activities = Repo.all(q)
end
- defp make_date do
- DateTime.utc_now() |> DateTime.to_iso8601()
- end
-
# DEPRECATED mostly, context objects are now created at insertion time.
def context_to_conversation_id(context) do
with %Object{id: id} <- Object.get_cached_by_ap_id(context) do
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index 0ccf937b0..786849aa3 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -1,9 +1,7 @@
defmodule Pleroma.Web.TwitterAPI.Controller do
use Pleroma.Web, :controller
- alias Pleroma.Formatter
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
alias Pleroma.{Repo, Activity, Object, User, Notification}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
@@ -155,7 +153,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|> render(NotificationView, "notification.json", %{notifications: notifications, for: user})
end
- def notifications_read(%{assigns: %{user: user}} = conn, _) do
+ def notifications_read(%{assigns: %{user: _user}} = conn, _) do
bad_request_reply(conn, "You need to specify latest_id")
end
@@ -416,7 +414,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
end
- def approve_friend_request(conn, %{"user_id" => uid} = params) do
+ def approve_friend_request(conn, %{"user_id" => uid} = _params) do
with followed <- conn.assigns[:user],
uid when is_number(uid) <- String.to_integer(uid),
%User{} = follower <- Repo.get(User, uid),
@@ -436,7 +434,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
end
- def deny_friend_request(conn, %{"user_id" => uid} = params) do
+ def deny_friend_request(conn, %{"user_id" => uid} = _params) do
with followed <- conn.assigns[:user],
uid when is_number(uid) <- String.to_integer(uid),
%User{} = follower <- Repo.get(User, uid),
diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex
index da3f68ecb..63d3302e0 100644
--- a/lib/pleroma/web/xml/xml.ex
+++ b/lib/pleroma/web/xml/xml.ex
@@ -28,12 +28,12 @@ defmodule Pleroma.Web.XML do
|> :xmerl_scan.string()
doc
- catch
- :exit, _error ->
+ rescue
+ _e ->
Logger.debug("Couldn't parse XML: #{inspect(text)}")
:error
- rescue
- e ->
+ catch
+ :exit, _error ->
Logger.debug("Couldn't parse XML: #{inspect(text)}")
:error
end