From 59770c3f5c9a038dbde6b2e1cd1551a7b8f1672b Mon Sep 17 00:00:00 2001 From: Thog Date: Sun, 19 Nov 2017 02:22:07 +0100 Subject: [PATCH] Fix all compilation warnings --- lib/pleroma/PasswordResetToken.ex | 6 ++-- lib/pleroma/notification.ex | 2 +- lib/pleroma/object.ex | 2 +- lib/pleroma/plugs/oauth_plug.ex | 2 +- lib/pleroma/user.ex | 11 +++--- lib/pleroma/web/activity_pub/activity_pub.ex | 7 ++-- lib/pleroma/web/activity_pub/utils.ex | 6 ++-- lib/pleroma/web/common_api/utils.ex | 2 +- lib/pleroma/web/federator/federator.ex | 12 +++---- .../mastodon_api/mastodon_api_controller.ex | 27 +++++++-------- .../web/mastodon_api/mastodon_socket.ex | 6 ++-- .../web/mastodon_api/views/account_view.ex | 2 +- .../web/ostatus/activity_representer.ex | 8 ++--- lib/pleroma/web/ostatus/feed_representer.ex | 2 +- .../web/ostatus/handlers/delete_handler.ex | 6 ++-- lib/pleroma/web/ostatus/ostatus.ex | 5 ++- lib/pleroma/web/ostatus/ostatus_controller.ex | 4 +-- lib/pleroma/web/streamer.ex | 34 +++++++++---------- .../representers/activity_representer.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 5 ++- .../web/twitter_api/twitter_api_controller.ex | 16 ++++----- .../web/twitter_api/views/user_view.ex | 6 ++-- lib/pleroma/web/web_finger/web_finger.ex | 2 +- lib/pleroma/web/xml/xml.ex | 4 +-- lib/transports.ex | 2 +- lib/xml_builder.ex | 2 +- 26 files changed, 89 insertions(+), 94 deletions(-) diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex index 79e60bf69..52b1fcd50 100644 --- a/lib/pleroma/PasswordResetToken.ex +++ b/lib/pleroma/PasswordResetToken.ex @@ -1,7 +1,7 @@ defmodule Pleroma.PasswordResetToken do use Ecto.Schema - import Ecto.{Changeset, Query} + import Ecto.Changeset alias Pleroma.{User, PasswordResetToken, Repo} @@ -26,7 +26,7 @@ def create_token(%User{} = user) do end def used_changeset(struct) do - changeset = struct + struct |> cast(%{}, []) |> put_change(:used, true) end @@ -34,7 +34,7 @@ def used_changeset(struct) do def reset_password(token, data) do with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}), %User{} = user <- Repo.get(User, token.user_id), - {:ok, user} <- User.reset_password(user, data), + {:ok, _user} <- User.reset_password(user, data), {:ok, token} <- Repo.update(used_changeset(token)) do {:ok, token} else diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 65e3265d4..241d6a9e0 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -67,7 +67,7 @@ def dismiss(%{id: user_id} = _user, id) do end end - def create_notifications(%Activity{id: id, data: %{"to" => to, "type" => type}} = activity) when type in ["Create", "Like", "Announce", "Follow"] do + def create_notifications(%Activity{id: _, data: %{"to" => _, "type" => type}} = activity) when type in ["Create", "Like", "Announce", "Follow"] do users = User.get_notified_from_activity(activity) notifications = Enum.map(users, fn (user) -> create_notification(activity, user) end) diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index a5a1d6a76..30ba7b57a 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -15,7 +15,7 @@ def create(data) do end def change(struct, params \\ %{}) do - changeset = struct + struct |> cast(params, [:data]) |> validate_required([:data]) |> unique_constraint(:ap_id, name: :objects_unique_apid_index) diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 8366e35af..775423bb1 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -9,7 +9,7 @@ def init(options) do end def call(%{assigns: %{user: %User{}}} = conn, _), do: conn - def call(conn, opts) do + def call(conn, _) do token = case get_req_header(conn, "authorization") do ["Bearer " <> header] -> header _ -> get_session(conn, :oauth_token) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 56502e897..fbeeef003 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -5,7 +5,6 @@ defmodule Pleroma.User do alias Pleroma.{Repo, User, Object, Web, Activity, Notification} alias Comeonin.Pbkdf2 alias Pleroma.Web.{OStatus, Websub} - alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils schema "users" do @@ -89,7 +88,7 @@ def remote_user_creation(params) do end def update_changeset(struct, params \\ %{}) do - changeset = struct + struct |> cast(params, [:bio, :name]) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) @@ -159,7 +158,7 @@ def follow(%User{} = follower, %User{} = followed) do |> follow_changeset(%{following: following}) |> Repo.update - {:ok, followed} = update_follower_count(followed) + {:ok, _} = update_follower_count(followed) follower end @@ -214,7 +213,7 @@ def get_or_fetch_by_nickname(nickname) do with %User{} = user <- get_by_nickname(nickname) do user else _e -> - with [nick, domain] <- String.split(nickname, "@"), + with [_nick, _domain] <- String.split(nickname, "@"), {:ok, user} <- OStatus.make_user(nickname) do user else _e -> nil @@ -276,7 +275,7 @@ def update_follower_count(%User{} = user) do Repo.update(cs) end - def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) do + def get_notified_from_activity(%Activity{data: %{"to" => to}}) do query = from u in User, where: u.ap_id in ^to, where: u.local == true @@ -284,7 +283,7 @@ def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) do Repo.all(query) end - def get_recipients_from_activity(%Activity{data: %{"to" => to}} = activity) do + def get_recipients_from_activity(%Activity{data: %{"to" => to}}) do query = from u in User, where: u.local == true diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index b4e59050b..4aade6e40 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1,6 +1,5 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do - alias Pleroma.{Activity, Repo, Object, Upload, User, Web, Notification} - alias Ecto.{Changeset, UUID} + alias Pleroma.{Activity, Repo, Object, Upload, User, Notification} import Ecto.Query import Pleroma.Web.ActivityPub.Utils require Logger @@ -34,7 +33,7 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil, loca end # TODO: This is weird, maybe we shouldn't check here if we can make the activity. - def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, activity_id \\ nil, local \\ true) do + def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, local \\ true) do with nil <- get_existing_like(ap_id, object), like_data <- make_like_data(user, object, activity_id), {:ok, activity} <- insert(like_data, local), @@ -56,7 +55,7 @@ def unlike(%User{} = actor, %Object{} = object) do end end - def announce(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, activity_id \\ nil, local \\ true) do + def announce(%User{ap_id: _} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, local \\ true) do with announce_data <- make_announce_data(user, object, activity_id), {:ok, activity} <- insert(announce_data, local), {:ok, object} <- add_announce_to_object(activity, object), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 4e3a7e2bd..51fac6fe2 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -64,7 +64,7 @@ def lazy_put_object_defaults(map) do Inserts a full object if it is contained in an activity. """ def insert_full_object(%{"object" => object_data}) when is_map(object_data) do - with {:ok, object} <- Object.create(object_data) do + with {:ok, _} <- Object.create(object_data) do :ok end end @@ -88,7 +88,7 @@ def update_object_in_activities(%{data: %{"id" => id}} = object) do @doc """ Returns an existing like if a user already liked an object """ - def get_existing_like(actor, %{data: %{"id" => id}} = object) do + def get_existing_like(actor, %{data: %{"id" => id}}) do query = from activity in Activity, where: fragment("(?)->>'actor' = ?", activity.data, ^actor), # this is to use the index @@ -201,7 +201,7 @@ def make_unfollow_data(follower, followed, follow_activity) do def make_create_data(params, additional) do published = params.published || make_date() - activity = %{ + %{ "type" => "Create", "to" => params.to |> Enum.uniq, "actor" => params.actor.ap_id, diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 7cce77b10..1a23b1ad2 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -57,7 +57,7 @@ def add_attachments(text, attachments) do Enum.join([text | attachment_text], "
") end - def format_input(text, mentions, tags) do + def format_input(text, mentions, _tags) do Phoenix.HTML.html_escape(text) |> elem(1) |> Formatter.linkify diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 4d6ebff8e..eccade883 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -71,7 +71,7 @@ def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback, end end - def handle(type, payload) do + def handle(type, _) do Logger.debug(fn -> "Unknown task: #{type}" end) {:error, "Don't know what do do with this"} end @@ -101,14 +101,14 @@ def handle_cast({:enqueue, type, payload}, {running_jobs, queue}) do {:noreply, {running_jobs, queue}} end + def handle_cast(m, state) do + IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") + {:noreply, state} + end + def handle_info({:DOWN, ref, :process, _pid, _reason}, {running_jobs, queue}) do running_jobs = :sets.del_element(ref, running_jobs) {running_jobs, queue} = maybe_start_job(running_jobs, queue) {:noreply, {running_jobs, queue}} end - - def handle_cast(m, state) do - IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") - {:noreply, state} - end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e1256c7b6..a3587ff44 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -4,12 +4,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.{CommonAPI, OStatus} alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Comeonin.Pbkdf2 import Ecto.Query - import Logger + require Logger def create_app(conn, params) do with cs <- App.register_changeset(%App{}, params) |> IO.inspect, @@ -75,7 +74,7 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do end end - def verify_credentials(%{assigns: %{user: user}} = conn, params) do + def verify_credentials(%{assigns: %{user: user}} = conn, _) do account = AccountView.render("account.json", %{user: user}) json(conn, account) end @@ -207,7 +206,7 @@ def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do end end - def post_status(%{assigns: %{user: user}} = conn, %{"status" => status} = params) do + def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do params = params |> Map.put("in_reply_to_status_id", params["in_reply_to_id"]) @@ -293,7 +292,7 @@ def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do render conn, AccountView, "relationships.json", %{user: user, targets: targets} end - def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) do + def upload(%{assigns: %{user: _}} = conn, %{"file" => file}) do with {:ok, object} <- ActivityPub.upload(file) do data = object.data |> Map.put("id", object.id) @@ -303,7 +302,7 @@ def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) do end def favourited_by(conn, %{"id" => id}) do - with %Activity{data: %{"object" => %{"likes" => likes} = data}} <- Repo.get(Activity, id) do + with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do q = from u in User, where: u.ap_id in ^likes users = Repo.all(q) @@ -356,10 +355,10 @@ def following(conn, %{"id" => id}) do def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do with %User{} = followed <- Repo.get(User, id), {:ok, follower} <- User.follow(follower, followed), - {:ok, activity} <- ActivityPub.follow(follower, followed) do + {:ok, _activity} <- ActivityPub.follow(follower, followed) do render conn, AccountView, "relationship.json", %{user: follower, target: followed} else - {:error, message} = err -> + {:error, message} -> conn |> put_resp_content_type("application/json") |> send_resp(403, Poison.encode!(%{"error" => message})) @@ -369,10 +368,10 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do with %User{} = followed <- Repo.get_by(User, nickname: uri), {:ok, follower} <- User.follow(follower, followed), - {:ok, activity} <- ActivityPub.follow(follower, followed) do + {:ok, _activity} <- ActivityPub.follow(follower, followed) do render conn, AccountView, "account.json", %{user: followed} else - {:error, message} = err -> + {:error, message} -> conn |> put_resp_content_type("application/json") |> send_resp(403, Poison.encode!(%{"error" => message})) @@ -397,7 +396,7 @@ def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do {:ok, blocker} <- User.block(blocker, blocked) do render conn, AccountView, "relationship.json", %{user: blocker, target: blocked} else - {:error, message} = err -> + {:error, message} -> conn |> put_resp_content_type("application/json") |> send_resp(403, Poison.encode!(%{"error" => message})) @@ -409,7 +408,7 @@ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do {:ok, blocker} <- User.unblock(blocker, blocked) do render conn, AccountView, "relationship.json", %{user: blocker, target: blocked} else - {:error, message} = err -> + {:error, message} -> conn |> put_resp_content_type("application/json") |> send_resp(403, Poison.encode!(%{"error" => message})) @@ -459,7 +458,7 @@ def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) d json(conn, res) end - def favourites(%{assigns: %{user: user}} = conn, params) do + def favourites(%{assigns: %{user: user}} = conn, _) do params = conn |> Map.put("type", "Create") |> Map.put("favorited_by", user.ap_id) @@ -556,7 +555,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do end end - def login(conn, params) do + def login(conn, _) do conn |> render(MastodonView, "login.html") end diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex index 1d276e64a..fe71ea271 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex @@ -22,9 +22,9 @@ def connect(params, socket) do end end - def id(socket), do: nil + def id(_), do: nil - def handle(:text, message, state) do + def handle(:text, message, _state) do IO.inspect message #| :ok #| state @@ -34,7 +34,7 @@ def handle(:text, message, state) do {:text, message} end - def handle(:closed, reason, %{socket: socket}) do + def handle(:closed, _, %{socket: socket}) do topic = socket.assigns[:topic] Pleroma.Web.Streamer.remove_socket(topic, socket) end diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 16322cf21..02f1e60bb 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.CommonAPI.Utils - defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href + defp image_url(%{"url" => [ %{ "href" => href } | _ ]}), do: href defp image_url(_), do: nil def render("accounts.json", %{users: users} = opts) do diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 2bff57e76..cfc342fca 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -108,7 +108,7 @@ def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) d updated_at = activity.data["published"] inserted_at = activity.data["published"] - in_reply_to = get_in_reply_to(activity.data) + _in_reply_to = get_in_reply_to(activity.data) author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] mentions = activity.data["to"] |> get_mentions @@ -136,7 +136,7 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho updated_at = activity.data["published"] inserted_at = activity.data["published"] - in_reply_to = get_in_reply_to(activity.data) + _in_reply_to = get_in_reply_to(activity.data) author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] retweeted_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) @@ -233,6 +233,8 @@ def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author) ] ++ author end + def to_simple_form(_, _, _), do: nil + def wrap_with_entry(simple_form) do [{ :entry, [ @@ -244,6 +246,4 @@ def wrap_with_entry(simple_form) do ], simple_form }] end - - def to_simple_form(_, _, _), do: nil end diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 6b67b8ddf..08710f246 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -2,7 +2,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter} - def to_simple_form(user, activities, users) do + def to_simple_form(user, activities, _users) do most_recent_update = (List.first(activities) || user).updated_at |> NaiveDateTime.to_iso8601 diff --git a/lib/pleroma/web/ostatus/handlers/delete_handler.ex b/lib/pleroma/web/ostatus/handlers/delete_handler.ex index 29fe4052c..4f3016b65 100644 --- a/lib/pleroma/web/ostatus/handlers/delete_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/delete_handler.ex @@ -1,10 +1,10 @@ defmodule Pleroma.Web.OStatus.DeleteHandler do require Logger - alias Pleroma.Web.{XML, OStatus} - alias Pleroma.{Activity, Object, Repo} + alias Pleroma.Web.XML + alias Pleroma.Object alias Pleroma.Web.ActivityPub.ActivityPub - def handle_delete(entry, doc \\ nil) do + def handle_delete(entry, _doc \\ nil) do with id <- XML.string_from_xpath("//id", entry), object when not is_nil(object) <- Object.get_by_ap_id(id), {:ok, delete} <- ActivityPub.delete(object, false) do diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index b0d2dda5d..745539b3e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus do alias Pleroma.{Repo, User, Web, Object, Activity} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.OStatus.{FollowHandler, NoteHandler, DeleteHandler} @@ -112,7 +111,7 @@ def get_or_try_fetching(entry) do with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do {:ok, activity} - else e -> + else _ -> Logger.debug("Couldn't get, will try to fetch") with href when not is_nil(href) <- string_from_xpath("//activity:object[1]/link[@type=\"text/html\"]/@href", entry), {:ok, [favorited_activity]} <- fetch_activity_from_url(href) do @@ -191,7 +190,7 @@ def maybe_update(doc, user) do false <- new_data == old_data do change = Ecto.Changeset.change(user, new_data) Repo.update(change) - else e -> + else _ -> {:ok, user} end end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 67688ace4..1ac07546f 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -46,7 +46,7 @@ defp decode_or_retry(body) do with [decoded | _] <- Pleroma.Web.Salmon.decode(body), doc <- XML.parse_document(decoded), uri when not is_nil(uri) <- XML.string_from_xpath("/entry/author[1]/uri", doc), - {:ok, user} <- Pleroma.Web.OStatus.make_user(uri, true), + {:ok, _} <- Pleroma.Web.OStatus.make_user(uri, true), {:ok, magic_key} <- Pleroma.Web.Salmon.fetch_magic_key(body), {:ok, doc} <- Pleroma.Web.Salmon.decode_and_validate(magic_key, body) do {:ok, doc} @@ -54,7 +54,7 @@ defp decode_or_retry(body) do end end - def salmon_incoming(conn, params) do + def salmon_incoming(conn, _) do {:ok, body, _conn} = read_body(conn) {:ok, doc} = decode_or_retry(body) diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 9f1080015..d64e6c393 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -1,7 +1,6 @@ defmodule Pleroma.Web.Streamer do use GenServer require Logger - import Plug.Conn alias Pleroma.{User, Notification} def start_link do @@ -38,17 +37,6 @@ def handle_cast(%{action: :ping}, topics) do {:noreply, topics} end - def push_to_socket(topics, topic, item) do - Enum.each(topics[topic] || [], fn (socket) -> - json = %{ - event: "update", - payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Poison.encode! - } |> Poison.encode! - - send socket.transport_pid, {:text, json} - end) - end - def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item}, topics) do topic = "user:#{item.user_id}" Enum.each(topics[topic] || [], fn (socket) -> @@ -80,11 +68,6 @@ def handle_cast(%{action: :stream, topic: topic, item: item}, topics) do {:noreply, topics} end - defp internal_topic("user", socket) do - "user:#{socket.assigns[:user].id}" - end - defp internal_topic(topic, socket), do: topic - def handle_cast(%{action: :add, topic: topic, socket: socket}, sockets) do topic = internal_topic(topic, socket) sockets_for_topic = sockets[topic] || [] @@ -109,4 +92,21 @@ def handle_cast(m, state) do IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") {:noreply, state} end + + def push_to_socket(topics, topic, item) do + Enum.each(topics[topic] || [], fn (socket) -> + json = %{ + event: "update", + payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Poison.encode! + } |> Poison.encode! + + send socket.transport_pid, {:text, json} + end) + end + + defp internal_topic("user", socket) do + "user:#{socket.assigns[:user].id}" + end + + defp internal_topic(topic, _), do: topic end diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index b17013d87..1f11bc9ac 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -97,7 +97,7 @@ def to_map(%Activity{data: %{"type" => "Undo", "published" => created_at, "objec } end - def to_map(%Activity{data: %{"type" => "Delete", "published" => created_at, "object" => deleted_object }} = activity, %{user: user} = opts) do + def to_map(%Activity{data: %{"type" => "Delete", "published" => created_at, "object" => _ }} = activity, %{user: user} = opts) do created_at = created_at |> Utils.date_to_asctime %{ diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index baa3dac96..d04a81cd4 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -4,12 +4,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.{OStatus, CommonAPI} - alias Pleroma.Formatter import Ecto.Query @httpoison Application.get_env(:pleroma, :httpoison) - def create_status(%User{} = user, %{"status" => status} = data) do + def create_status(%User{} = user, %{"status" => _} = data) do CommonAPI.post(user, data) end @@ -216,7 +215,7 @@ def get_user(user \\ nil, params) do end end - defp parse_int(string, default \\ nil) + defp parse_int(string, default) defp parse_int(string, default) when is_binary(string) do with {n, _} <- Integer.parse(string) do n diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index e319cfb8c..1a706029a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.CommonAPI - alias Pleroma.{Repo, Activity, User, Object} + alias Pleroma.{Repo, Activity, User} alias Pleroma.Web.ActivityPub.ActivityPub alias Ecto.Changeset @@ -13,7 +13,7 @@ def verify_credentials(%{assigns: %{user: user}} = conn, _params) do render(conn, UserView, "show.json", %{user: user}) end - def status_update(%{assigns: %{user: user}} = conn, %{"status" => status_text} = status_data) do + def status_update(%{assigns: %{user: user}} = conn, %{"status" => _} = status_data) do with media_ids <- extract_media_ids(status_data), {:ok, activity} <- TwitterAPI.create_status(user, Map.put(status_data, "media_ids", media_ids)) do conn @@ -215,8 +215,8 @@ def update_banner(%{assigns: %{user: user}} = conn, params) do with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}), new_info <- Map.put(user.info, "banner", object.data), change <- User.info_changeset(user, %{info: new_info}), - {:ok, user} <- Repo.update(change) do - %{"url" => [ %{ "href" => href } | t ]} = object.data + {:ok, _user} <- Repo.update(change) do + %{"url" => [ %{ "href" => href } | _ ]} = object.data response = %{ url: href } |> Poison.encode! conn |> json_reply(200, response) @@ -227,8 +227,8 @@ def update_background(%{assigns: %{user: user}} = conn, params) do with {:ok, object} <- ActivityPub.upload(params), new_info <- Map.put(user.info, "background", object.data), change <- User.info_changeset(user, %{info: new_info}), - {:ok, user} <- Repo.update(change) do - %{"url" => [ %{ "href" => href } | t ]} = object.data + {:ok, _user} <- Repo.update(change) do + %{"url" => [ %{ "href" => href } | _ ]} = object.data response = %{ url: href } |> Poison.encode! conn |> json_reply(200, response) @@ -254,7 +254,7 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" => mrn <- max(id, user.info["most_recent_notification"] || 0), updated_info <- Map.put(info, "most_recent_notification", mrn), changeset <- User.info_changeset(user, %{info: updated_info}), - {:ok, user} <- Repo.update(changeset) do + {:ok, _user} <- Repo.update(changeset) do conn |> json_reply(200, Poison.encode!(mrn)) else @@ -311,7 +311,7 @@ def update_profile(%{assigns: %{user: user}} = conn, params) do end end - def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do + def search(%{assigns: %{user: user}} = conn, %{"q" => _query} = params) do conn |> json(TwitterAPI.search(user, params)) end diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 6c5676c04..3dc18eff8 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -11,9 +11,6 @@ def render("index.json", %{users: users, for: user}) do render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user) end - defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href - defp image_url(_), do: nil - def render("user.json", %{user: user = %User{}} = assigns) do image = User.avatar_url(user) {following, follows_you, statusnet_blocking} = if assigns[:for] do @@ -63,4 +60,7 @@ def render("short.json", %{user: %User{ "screen_name" => nickname } end + + defp image_url(%{"url" => [ %{ "href" => href } | _ ]}), do: href + defp image_url(_), do: nil end diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 7cbafe11f..026d2f98b 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -89,7 +89,7 @@ def find_lrdd_template(domain) do with {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- @httpoison.get("http://#{domain}/.well-known/host-meta", [], follow_redirect: true) do get_template_from_xml(body) else - e -> + _ -> with {:ok, %{body: body}} <- @httpoison.get("https://#{domain}/.well-known/host-meta", []) do get_template_from_xml(body) else diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index 63580c1f8..026672ad1 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Web.XML do require Logger - def string_from_xpath(xpath, :error), do: nil + def string_from_xpath(_, :error), do: nil def string_from_xpath(xpath, doc) do {:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc) @@ -20,7 +20,7 @@ def parse_document(text) do doc catch - :exit, error -> + :exit, _error -> Logger.debug("Couldn't parse xml: #{inspect(text)}") :error end diff --git a/lib/transports.ex b/lib/transports.ex index 5600a4fdd..a820aa778 100644 --- a/lib/transports.ex +++ b/lib/transports.ex @@ -61,7 +61,7 @@ def ws_handle(op, data, state) do end end - def ws_info({op, data} = tuple, state) do + def ws_info({_,_} = tuple, state) do {:reply, tuple, state} end diff --git a/lib/xml_builder.ex b/lib/xml_builder.ex index c6d144903..52358c437 100644 --- a/lib/xml_builder.ex +++ b/lib/xml_builder.ex @@ -37,6 +37,6 @@ defp make_open_tag(tag, attributes) do "#{attribute}=\"#{value}\"" end |> Enum.join(" ") - [tag, attributes_string] |> Enum.join(" ") |> String.strip + [tag, attributes_string] |> Enum.join(" ") |> String.trim end end