From ab4aa5720aeac8541fbf99e6c98e7260cb19d41e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 20:59:01 +0000 Subject: [PATCH 01/11] Fix a bunch of unused variable warnings --- lib/pleroma/plugs/http_signature.ex | 4 ++-- lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 2 +- lib/pleroma/web/activity_pub/transmogrifier.ex | 4 ++-- lib/pleroma/web/common_api/utils.ex | 4 ++-- lib/pleroma/web/federator/federator.ex | 8 ++++---- lib/pleroma/web/http_signatures/http_signatures.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 4 ++-- lib/pleroma/web/xml/xml.ex | 2 +- test/support/builders/activity_builder.ex | 2 +- test/support/httpoison_mock.ex | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/pleroma/plugs/http_signature.ex b/lib/pleroma/plugs/http_signature.ex index 8b9ccdd2d..efde652f5 100644 --- a/lib/pleroma/plugs/http_signature.ex +++ b/lib/pleroma/plugs/http_signature.ex @@ -7,11 +7,11 @@ def init(options) do options end - def call(%{assigns: %{valid_signature: true}} = conn, opts) do + def call(%{assigns: %{valid_signature: true}} = conn, _opts) do conn end - def call(conn, opts) do + def call(conn, _opts) do user = conn.params["actor"] Logger.debug("Checking sig for #{user}") [signature | _] = get_req_header(conn, "signature") diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index ea1af0f4d..ad28cbfe3 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -70,7 +70,7 @@ def filter(object) do {:ok, object} <- check_ftl_removal(actor_info, object) do {:ok, object} else - e -> {:reject, nil} + _e -> {:reject, nil} end end end diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 2871a2544..221bc7dab 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -143,12 +143,12 @@ def handle_incoming( 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 %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), - {:ok, activity, object} <- ActivityPub.like(actor, object, id, false) do + {:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do {:ok, activity} else _e -> :error diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 3c092d524..b142eda95 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -49,7 +49,7 @@ def to_for_user_and_mentions(user, mentions, inReplyTo, "private") do {[user.follower_address | to], cc} end - def to_for_user_and_mentions(user, mentions, inReplyTo, "direct") do + def to_for_user_and_mentions(_user, mentions, inReplyTo, "direct") do mentioned_users = Enum.map(mentions, fn {_, %{ap_id: ap_id}} -> ap_id end) if inReplyTo do @@ -69,7 +69,7 @@ def make_content_html(status, mentions, attachments, tags, no_attachment_links \ def make_context(%Activity{data: %{"context" => context}}), do: context def make_context(_), do: Utils.generate_context_id() - def maybe_add_attachments(text, attachments, _no_links = true), do: text + def maybe_add_attachments(text, _attachments, _no_links = true), do: text def maybe_add_attachments(text, attachments, _no_links) do add_attachments(text, attachments) diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 8335add9c..c4c18192c 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -89,12 +89,12 @@ def handle(:incoming_ap_doc, params) do with {:ok, _user} <- ap_enabled_actor(params["actor"]), nil <- Activity.get_by_ap_id(params["id"]), - {:ok, activity} <- Transmogrifier.handle_incoming(params) do + {:ok, _activity} <- Transmogrifier.handle_incoming(params) do else %Activity{} -> Logger.info("Already had #{params["id"]}") - e -> + _e -> # Just drop those for now Logger.info("Unhandled activity") Logger.info(Poison.encode!(params, pretty: 2)) @@ -154,7 +154,7 @@ def maybe_start_job(running_jobs, queue) do end end - def handle_cast({:enqueue, type, payload, priority}, state) + def handle_cast({:enqueue, type, payload, _priority}, state) when type in [:incoming_doc, :incoming_ap_doc] do %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state i_queue = enqueue_sorted(i_queue, {type, payload}, 1) @@ -162,7 +162,7 @@ def handle_cast({:enqueue, type, payload, priority}, state) {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}} end - def handle_cast({:enqueue, type, payload, priority}, state) do + def handle_cast({:enqueue, type, payload, _priority}, state) do %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state o_queue = enqueue_sorted(o_queue, {type, payload}, 1) {o_running_jobs, o_queue} = maybe_start_job(o_running_jobs, o_queue) diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index 0ea3b7554..9035f5eb6 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -45,7 +45,7 @@ def validate_conn(conn) do end end else - e -> + _e -> Logger.debug("Could not public key!") false end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index c12cd7f8a..5a843a3ab 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -184,7 +184,7 @@ defp parse_int(string, default) when is_binary(string) do defp parse_int(_, default), do: default - def search(user, %{"q" => query} = params) do + def search(_user, %{"q" => query} = params) do limit = parse_int(params["rpp"], 20) page = parse_int(params["page"], 1) offset = (page - 1) * limit @@ -206,7 +206,7 @@ def search(user, %{"q" => query} = params) do order_by: [desc: :inserted_at] ) - activities = Repo.all(q) + _activities = Repo.all(q) end defp make_date do diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index 8b609f695..36430a3fa 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -14,7 +14,7 @@ def string_from_xpath(xpath, doc) do if res == "", do: nil, else: res catch - e -> + _e -> Logger.debug("Couldn't find xpath #{xpath} in XML doc") nil end diff --git a/test/support/builders/activity_builder.ex b/test/support/builders/activity_builder.ex index d9c188955..eb72d5ba9 100644 --- a/test/support/builders/activity_builder.ex +++ b/test/support/builders/activity_builder.ex @@ -26,7 +26,7 @@ def insert(data \\ %{}, opts \\ %{}) do end def insert_list(times, data \\ %{}, opts \\ %{}) do - Enum.map(1..times, fn n -> + Enum.map(1..times, fn _n -> {:ok, activity} = insert(data, opts) activity end) diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index ba35c4460..4a5a9ea85 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -367,7 +367,7 @@ def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _hea def post( "https://social.heldscal.la/main/push/hub", - {:form, data}, + {:form, _data}, "Content-type": "application/x-www-form-urlencoded" ) do {:ok, @@ -711,11 +711,11 @@ def get(url, body, headers) do }"} end - def post(url, body, headers) do + def post(url, _body, _headers) do {:error, "Not implemented the mock response for post #{inspect(url)}"} end - def post(url, body, headers, options) do + def post(url, _body, _headers, _options) do {:error, "Not implemented the mock response for post #{inspect(url)}"} end end From 943820ae295dc52b2cf43ebb539093e24390edba Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:16:02 +0000 Subject: [PATCH 02/11] More unused variables --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 +++++----- lib/pleroma/web/activity_pub/transmogrifier.ex | 14 +++++++------- lib/pleroma/web/activity_pub/views/user_view.ex | 4 ++-- lib/pleroma/web/twitter_api/views/activity_view.ex | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 3ddc009a1..fde6e12d7 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -66,7 +66,7 @@ def create(%{to: to, actor: actor, context: context, object: object} = params) d ), {:ok, activity} <- insert(create_data, local), :ok <- maybe_federate(activity), - {:ok, actor} <- User.increase_note_count(actor) do + {:ok, _actor} <- User.increase_note_count(actor) do {:ok, activity} end end @@ -177,7 +177,7 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)), {:ok, activity} <- insert(data, local), :ok <- maybe_federate(activity), - {:ok, actor} <- User.decrease_note_count(user) do + {:ok, _actor} <- User.decrease_note_count(user) do {:ok, activity} end end @@ -236,7 +236,7 @@ defp restrict_tag(query, %{"tag" => tag}) do defp restrict_tag(query, _), do: query - defp restrict_recipients(query, [], user), do: query + defp restrict_recipients(query, [], _user), do: query defp restrict_recipients(query, recipients, nil) do from(activity in query, where: fragment("? && ?", ^recipients, activity.recipients)) @@ -400,7 +400,7 @@ def fetch_and_prepare_user_from_ap_id(ap_id) do end def make_user_from_ap_id(ap_id) do - if user = User.get_by_ap_id(ap_id) do + if _user = User.get_by_ap_id(ap_id) do Transmogrifier.upgrade_user_from_ap_id(ap_id) else with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do @@ -496,7 +496,7 @@ def fetch_object_from_id(id) do object = %Object{} -> {:ok, object} - e -> + _e -> Logger.info("Couldn't get object via AP, trying out OStatus fetching...") case OStatus.fetch_activity_from_url(id) do diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 221bc7dab..da6562dcd 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -156,12 +156,12 @@ def handle_incoming( 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 %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), - {:ok, activity, object} <- ActivityPub.announce(actor, object, id, false) do + {:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false) do {:ok, activity} else _e -> :error @@ -202,7 +202,7 @@ def handle_incoming( # TODO: Make secure. def handle_incoming( - %{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => id} = data + %{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => _id} = _data ) do object_id = case object_id do @@ -210,13 +210,13 @@ def handle_incoming( id -> id end - with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), + with %User{} = _actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), {:ok, activity} <- ActivityPub.delete(object, false) do {:ok, activity} else - e -> :error + _e -> :error end end @@ -272,7 +272,7 @@ def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = obj {:ok, data} end - def prepare_outgoing(%{"type" => type} = data) do + def prepare_outgoing(%{"type" => _type} = data) do data = data |> maybe_fix_object_url @@ -286,7 +286,7 @@ def maybe_fix_object_url(data) do case ActivityPub.fetch_object_from_id(data["object"]) do {:ok, relative_object} -> if relative_object.data["external_url"] do - data = + _data = data |> Map.put("object", relative_object.data["external_url"]) else diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 92afd0872..733e5fb57 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -47,11 +47,11 @@ def render("user.json", %{user: user}) do |> Map.merge(Utils.make_json_ld_header()) end - def collection(collection, iri, page, total \\ nil) do + def collection(collection, iri, page, _total \\ nil) do offset = (page - 1) * 10 items = Enum.slice(collection, offset, 10) items = Enum.map(items, fn user -> user.ap_id end) - total = total || length(collection) + _total = _total || length(collection) map = %{ "id" => "#{iri}?page=#{page}", diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 4e4433aed..580d4648c 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -31,7 +31,7 @@ defp query_users(user_ids) do end defp collect_context_ids(activities) do - contexts = + _contexts = activities |> Enum.reject(& &1.data["context_id"]) |> Enum.map(fn %{data: data} -> From 636f0fa40240f567a2171b347f0722d601ba63db Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:25:31 +0000 Subject: [PATCH 03/11] Clean up unused aliases and imports --- lib/mix/tasks/generate_password_reset.ex | 3 +-- lib/mix/tasks/register_user.ex | 1 - lib/mix/tasks/rm_user.ex | 3 +-- lib/pleroma/stats.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 2 +- lib/pleroma/web/channels/user_socket.ex | 1 - lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 2 +- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 1 - lib/pleroma/web/ostatus/activity_representer.ex | 1 - lib/pleroma/web/ostatus/handlers/note_handler.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 1 - lib/pleroma/web/twitter_api/twitter_api.ex | 1 - lib/pleroma/web/web_finger/web_finger.ex | 2 +- 14 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/mix/tasks/generate_password_reset.ex b/lib/mix/tasks/generate_password_reset.ex index e39134007..6bf640150 100644 --- a/lib/mix/tasks/generate_password_reset.ex +++ b/lib/mix/tasks/generate_password_reset.ex @@ -1,7 +1,6 @@ defmodule Mix.Tasks.GeneratePasswordReset do use Mix.Task - import Mix.Ecto - alias Pleroma.{Repo, User} + alias Pleroma.User @shortdoc "Generate password reset link for user" def run([nickname]) do diff --git a/lib/mix/tasks/register_user.ex b/lib/mix/tasks/register_user.ex index 4bec6b9d9..e74721c49 100644 --- a/lib/mix/tasks/register_user.ex +++ b/lib/mix/tasks/register_user.ex @@ -1,6 +1,5 @@ defmodule Mix.Tasks.RegisterUser do use Mix.Task - import Mix.Ecto alias Pleroma.{Repo, User} @shortdoc "Register user" diff --git a/lib/mix/tasks/rm_user.ex b/lib/mix/tasks/rm_user.ex index 6a698f360..27521b745 100644 --- a/lib/mix/tasks/rm_user.ex +++ b/lib/mix/tasks/rm_user.ex @@ -1,7 +1,6 @@ defmodule Mix.Tasks.RmUser do use Mix.Task - import Mix.Ecto - alias Pleroma.{User, Repo} + alias Pleroma.User @shortdoc "Permanently delete a user" def run([nickname]) do diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index 83b896a16..8478fe4ce 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Stats do import Ecto.Query - alias Pleroma.{User, Repo, Activity} + alias Pleroma.{User, Repo} def start_link do agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__) diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 12f61f5f0..d374fd91f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller - alias Pleroma.{User, Repo, Object, Activity} + alias Pleroma.{User, Object} alias Pleroma.Web.ActivityPub.{ObjectView, UserView, Transmogrifier} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.Federator diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index fd8918a7d..21b22b409 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -1,7 +1,6 @@ defmodule Pleroma.Web.UserSocket do use Phoenix.Socket alias Pleroma.User - alias Comeonin.Pbkdf2 ## Channels # channel "room:*", Pleroma.Web.RoomChannel diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 2c4b591d4..14a68929d 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -1,5 +1,5 @@ defmodule Pleroma.Web.CommonAPI do - alias Pleroma.{Repo, Activity, Object, User} + alias Pleroma.{Repo, Activity, Object} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Formatter diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b142eda95..57f8be894 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,5 +1,5 @@ defmodule Pleroma.Web.CommonAPI.Utils do - alias Pleroma.{Repo, Object, Formatter, User, Activity} + alias Pleroma.{Repo, Object, Formatter, Activity} alias Pleroma.Web.ActivityPub.Utils alias Calendar.Strftime diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 36a7802ed..aec77168a 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -1,7 +1,6 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do use Pleroma.Web, :controller - alias Pleroma.Web.Nodeinfo alias Pleroma.Stats alias Pleroma.Web diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 921a89bd0..e8841a856 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -1,7 +1,6 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do alias Pleroma.{Activity, User, Object} alias Pleroma.Web.OStatus.UserRepresenter - alias Pleroma.Formatter require Logger defp get_href(id) do diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index bd6e92238..0d4080291 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do require Logger alias Pleroma.Web.{XML, OStatus} - alias Pleroma.{Object, User, Activity} + alias Pleroma.{Object, Activity} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index a02f55fe6..f39ebaf2b 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -8,7 +8,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Web.XML alias Pleroma.Web.ActivityPub.ActivityPubController alias Pleroma.Web.ActivityPub.ActivityPub - import Ecto.Query def feed_redirect(conn, %{"nickname" => nickname} = params) do user = User.get_cached_by_nickname(nickname) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 5a843a3ab..44ea40a4e 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -1,7 +1,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do alias Pleroma.{User, Activity, Repo, Object} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.{OStatus, CommonAPI} import Ecto.Query diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index dc9ad2014..9fe3b2ca1 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Web.WebFinger do @httpoison Application.get_env(:pleroma, :httpoison) - alias Pleroma.{Repo, User, XmlBuilder} + alias Pleroma.{User, XmlBuilder} alias Pleroma.Web alias Pleroma.Web.{XML, Salmon, OStatus} require Jason From 42f1a098aa5f3e446964b439236b507d0002e837 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:26:33 +0000 Subject: [PATCH 04/11] Fix build. Too eager with the fixing of unused variables. == Compilation error in file lib/pleroma/web/activity_pub/views/user_view.ex == ** (CompileError) lib/pleroma/web/activity_pub/views/user_view.ex:54: undefined function _total/0 (stdlib) lists.erl:1338: :lists.foreach/2 (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 --- lib/pleroma/web/activity_pub/views/user_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 733e5fb57..d6bf71884 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -51,7 +51,7 @@ def collection(collection, iri, page, _total \\ nil) do offset = (page - 1) * 10 items = Enum.slice(collection, offset, 10) items = Enum.map(items, fn user -> user.ap_id end) - _total = _total || length(collection) + total = _total || length(collection) map = %{ "id" => "#{iri}?page=#{page}", From aaacebd906b0506b1d0f55df3047f0d730bd4b26 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:42:20 +0000 Subject: [PATCH 05/11] Fix unused variables, imports, and aliases --- lib/mix/tasks/fix_ap_users.ex | 1 - lib/pleroma/web/activity_pub/activity_pub_controller.ex | 2 +- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 2 +- lib/pleroma/web/twitter_api/views/notification_view.ex | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/mix/tasks/fix_ap_users.ex b/lib/mix/tasks/fix_ap_users.ex index 2523cdbcb..7e970850e 100644 --- a/lib/mix/tasks/fix_ap_users.ex +++ b/lib/mix/tasks/fix_ap_users.ex @@ -1,6 +1,5 @@ defmodule Mix.Tasks.FixApUsers do use Mix.Task - import Mix.Ecto import Ecto.Query alias Pleroma.{Repo, User} diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index d374fd91f..80aae4f0f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller alias Pleroma.{User, Object} - alias Pleroma.Web.ActivityPub.{ObjectView, UserView, Transmogrifier} + alias Pleroma.Web.ActivityPub.{ObjectView, UserView} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.Federator diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index df360644a..cbc2dd770 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -83,7 +83,7 @@ def render( end def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do - id = activity.data["object"]["inReplyTo"] + _id = activity.data["object"]["inReplyTo"] replied_to_activities[activity.data["object"]["inReplyTo"]] end diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index c7b1a5b95..ea540b34c 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -92,7 +92,7 @@ def do_remote_follow(conn, %{ with %User{} = user <- User.get_cached_by_nickname(username), true <- Pbkdf2.checkpw(password, user.password_hash), - %User{} = followed <- Repo.get(User, id), + %User{} = _followed <- Repo.get(User, id), {:ok, follower} <- User.follow(user, followee), {:ok, _activity} <- ActivityPub.follow(follower, followee) do conn diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index f41edea0b..9eeb3afdc 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -2,7 +2,6 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do use Pleroma.Web, :view alias Pleroma.{Notification, User} alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.MediaProxy alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.ActivityView From 79d41aa12e900423a9717187a94faceec7f014fd Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:48:30 +0000 Subject: [PATCH 06/11] Dirty hack to remove the warning warning: code block contains unused literal "internal -> Mastodon\n" (remove the literal or assign it to _ to avoid warnings) lib/pleroma/web/activity_pub/transmogrifier.ex --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index da6562dcd..01b3eab27 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -255,7 +255,7 @@ def prepare_object(object) do end @doc - """ + _ = """ internal -> Mastodon """ From a24eed0f575718f491f155a74febd9866cf2c09a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:53:52 +0000 Subject: [PATCH 07/11] That last change was stupid. Multiline comments in Elixir don't really exist. Instead we'll just pad with # intstead of playing stupid games with the compiler. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 01b3eab27..2b6a97aa0 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -254,10 +254,10 @@ def prepare_object(object) do |> set_reply_to_uri end - @doc - _ = """ - internal -> Mastodon - """ +# @doc +# """ +# internal -> Mastodon +# """ def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do object = From 2a402fb3958fe1775afc69075ba394dde0b112a0 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 21:59:21 +0000 Subject: [PATCH 08/11] Group response declarations together --- lib/pleroma/gopher/server.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index 82e241f21..f6abcd4d0 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -65,12 +65,6 @@ def link(name, selector, type \\ 1) do "#{type}#{name}\t#{selector}\t#{address}\t#{port}\r\n" end - def response("") do - info("Welcome to #{Keyword.get(@instance, :name, "Pleroma")}!") <> - link("Public Timeline", "/main/public") <> - link("Federated Timeline", "/main/all") <> ".\r\n" - end - def render_activities(activities) do activities |> Enum.reverse() @@ -93,6 +87,12 @@ def render_activities(activities) do |> Enum.join("\r\n") end + def response("") do + info("Welcome to #{Keyword.get(@instance, :name, "Pleroma")}!") <> + link("Public Timeline", "/main/public") <> + link("Federated Timeline", "/main/all") <> ".\r\n" + end + def response("/main/public") do posts = ActivityPub.fetch_public_activities(%{"type" => ["Create"], "local_only" => true}) From 14c0c6d16bd2c91ca02fc0c81dd0fb46ef8af41c Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 22:03:14 +0000 Subject: [PATCH 09/11] Fix formatting --- lib/pleroma/web/activity_pub/transmogrifier.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 2b6a97aa0..c6b99da2e 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -254,10 +254,10 @@ def prepare_object(object) do |> set_reply_to_uri end -# @doc -# """ -# internal -> Mastodon -# """ + # @doc + # """ + # internal -> Mastodon + # """ def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do object = From 31ea9cbcd8e359838faf6587db73005f090040e1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 22:28:13 +0000 Subject: [PATCH 10/11] Group def renders together to fix warning --- .../web/mastodon_api/views/status_view.ex | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index cbc2dd770..5c6fd05f3 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -82,19 +82,6 @@ def render( } 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"]] - end - - def get_reply_to(%{data: %{"object" => object}}, _) do - if object["inReplyTo"] && object["inReplyTo"] != "" do - Activity.get_create_activity_by_object_ap_id(object["inReplyTo"]) - else - nil - end - end - def render("status.json", %{activity: %{data: %{"object" => object}} = activity} = opts) do user = User.get_cached_by_ap_id(activity.data["actor"]) @@ -164,19 +151,6 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity} } end - def get_visibility(object) do - public = "https://www.w3.org/ns/activitystreams#Public" - to = object["to"] || [] - cc = object["cc"] || [] - - cond do - public in to -> "public" - public in cc -> "unlisted" - Enum.any?(to, &String.contains?(&1, "/followers")) -> "private" - true -> "direct" - end - end - def render("attachment.json", %{attachment: attachment}) do [%{"mediaType" => media_type, "href" => href} | _] = attachment["url"] @@ -199,4 +173,30 @@ def render("attachment.json", %{attachment: attachment}) do type: type } 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"]] + end + + def get_reply_to(%{data: %{"object" => object}}, _) do + if object["inReplyTo"] && object["inReplyTo"] != "" do + Activity.get_create_activity_by_object_ap_id(object["inReplyTo"]) + else + nil + end + end + + def get_visibility(object) do + public = "https://www.w3.org/ns/activitystreams#Public" + to = object["to"] || [] + cc = object["cc"] || [] + + cond do + public in to -> "public" + public in cc -> "unlisted" + Enum.any?(to, &String.contains?(&1, "/followers")) -> "private" + true -> "direct" + end + end end From 7a884d70d8fd92a44c35911509b248a902275e07 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 May 2018 22:31:46 +0000 Subject: [PATCH 11/11] Group def renders here as well --- .../web/activity_pub/views/user_view.ex | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index d6bf71884..156a12f26 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -47,25 +47,6 @@ def render("user.json", %{user: user}) do |> Map.merge(Utils.make_json_ld_header()) end - def collection(collection, iri, page, _total \\ nil) do - offset = (page - 1) * 10 - items = Enum.slice(collection, offset, 10) - items = Enum.map(items, fn user -> user.ap_id end) - total = _total || length(collection) - - map = %{ - "id" => "#{iri}?page=#{page}", - "type" => "OrderedCollectionPage", - "partOf" => iri, - "totalItems" => length(collection), - "orderedItems" => items - } - - if offset < length(collection) do - Map.put(map, "next", "#{iri}?page=#{page + 1}") - end - end - def render("following.json", %{user: user, page: page}) do query = User.get_friends_query(user) query = from(user in query, select: [:ap_id]) @@ -162,4 +143,23 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do page |> Map.merge(Utils.make_json_ld_header()) end end + + def collection(collection, iri, page, _total \\ nil) do + offset = (page - 1) * 10 + items = Enum.slice(collection, offset, 10) + items = Enum.map(items, fn user -> user.ap_id end) + total = _total || length(collection) + + map = %{ + "id" => "#{iri}?page=#{page}", + "type" => "OrderedCollectionPage", + "partOf" => iri, + "totalItems" => length(collection), + "orderedItems" => items + } + + if offset < length(collection) do + Map.put(map, "next", "#{iri}?page=#{page + 1}") + end + end end