Merge branch 'feature/fix-warnings' into 'develop'

Fix all compilation warnings

See merge request pleroma/pleroma!24
This commit is contained in:
lambda 2017-11-19 11:50:02 +00:00
commit a6f65083ae
26 changed files with 89 additions and 94 deletions

View File

@ -1,7 +1,7 @@
defmodule Pleroma.PasswordResetToken do defmodule Pleroma.PasswordResetToken do
use Ecto.Schema use Ecto.Schema
import Ecto.{Changeset, Query} import Ecto.Changeset
alias Pleroma.{User, PasswordResetToken, Repo} alias Pleroma.{User, PasswordResetToken, Repo}
@ -26,7 +26,7 @@ defmodule Pleroma.PasswordResetToken do
end end
def used_changeset(struct) do def used_changeset(struct) do
changeset = struct struct
|> cast(%{}, []) |> cast(%{}, [])
|> put_change(:used, true) |> put_change(:used, true)
end end
@ -34,7 +34,7 @@ defmodule Pleroma.PasswordResetToken do
def reset_password(token, data) do def reset_password(token, data) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}), with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
%User{} = user <- Repo.get(User, token.user_id), %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} <- Repo.update(used_changeset(token)) do
{:ok, token} {:ok, token}
else else

View File

@ -67,7 +67,7 @@ defmodule Pleroma.Notification do
end end
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) users = User.get_notified_from_activity(activity)
notifications = Enum.map(users, fn (user) -> create_notification(activity, user) end) notifications = Enum.map(users, fn (user) -> create_notification(activity, user) end)

View File

@ -15,7 +15,7 @@ defmodule Pleroma.Object do
end end
def change(struct, params \\ %{}) do def change(struct, params \\ %{}) do
changeset = struct struct
|> cast(params, [:data]) |> cast(params, [:data])
|> validate_required([:data]) |> validate_required([:data])
|> unique_constraint(:ap_id, name: :objects_unique_apid_index) |> unique_constraint(:ap_id, name: :objects_unique_apid_index)

View File

@ -9,7 +9,7 @@ defmodule Pleroma.Plugs.OAuthPlug do
end end
def call(%{assigns: %{user: %User{}}} = conn, _), do: conn 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 token = case get_req_header(conn, "authorization") do
["Bearer " <> header] -> header ["Bearer " <> header] -> header
_ -> get_session(conn, :oauth_token) _ -> get_session(conn, :oauth_token)

View File

@ -5,7 +5,6 @@ defmodule Pleroma.User do
alias Pleroma.{Repo, User, Object, Web, Activity, Notification} alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
alias Comeonin.Pbkdf2 alias Comeonin.Pbkdf2
alias Pleroma.Web.{OStatus, Websub} alias Pleroma.Web.{OStatus, Websub}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
schema "users" do schema "users" do
@ -89,7 +88,7 @@ defmodule Pleroma.User do
end end
def update_changeset(struct, params \\ %{}) do def update_changeset(struct, params \\ %{}) do
changeset = struct struct
|> cast(params, [:bio, :name]) |> cast(params, [:bio, :name])
|> unique_constraint(:nickname) |> unique_constraint(:nickname)
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
@ -159,7 +158,7 @@ defmodule Pleroma.User do
|> follow_changeset(%{following: following}) |> follow_changeset(%{following: following})
|> Repo.update |> Repo.update
{:ok, followed} = update_follower_count(followed) {:ok, _} = update_follower_count(followed)
follower follower
end end
@ -214,7 +213,7 @@ defmodule Pleroma.User do
with %User{} = user <- get_by_nickname(nickname) do with %User{} = user <- get_by_nickname(nickname) do
user user
else _e -> else _e ->
with [nick, domain] <- String.split(nickname, "@"), with [_nick, _domain] <- String.split(nickname, "@"),
{:ok, user} <- OStatus.make_user(nickname) do {:ok, user} <- OStatus.make_user(nickname) do
user user
else _e -> nil else _e -> nil
@ -276,7 +275,7 @@ defmodule Pleroma.User do
Repo.update(cs) Repo.update(cs)
end 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, query = from u in User,
where: u.ap_id in ^to, where: u.ap_id in ^to,
where: u.local == true where: u.local == true
@ -284,7 +283,7 @@ defmodule Pleroma.User do
Repo.all(query) Repo.all(query)
end 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, query = from u in User,
where: u.local == true where: u.local == true

View File

@ -1,6 +1,5 @@
defmodule Pleroma.Web.ActivityPub.ActivityPub do defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.{Activity, Repo, Object, Upload, User, Web, Notification} alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
alias Ecto.{Changeset, UUID}
import Ecto.Query import Ecto.Query
import Pleroma.Web.ActivityPub.Utils import Pleroma.Web.ActivityPub.Utils
require Logger require Logger
@ -34,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end end
# TODO: This is weird, maybe we shouldn't check here if we can make the activity. # 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), with nil <- get_existing_like(ap_id, object),
like_data <- make_like_data(user, object, activity_id), like_data <- make_like_data(user, object, activity_id),
{:ok, activity} <- insert(like_data, local), {:ok, activity} <- insert(like_data, local),
@ -56,7 +55,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end end
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), with announce_data <- make_announce_data(user, object, activity_id),
{:ok, activity} <- insert(announce_data, local), {:ok, activity} <- insert(announce_data, local),
{:ok, object} <- add_announce_to_object(activity, object), {:ok, object} <- add_announce_to_object(activity, object),

View File

@ -64,7 +64,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Inserts a full object if it is contained in an activity. Inserts a full object if it is contained in an activity.
""" """
def insert_full_object(%{"object" => object_data}) when is_map(object_data) do 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 :ok
end end
end end
@ -88,7 +88,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
@doc """ @doc """
Returns an existing like if a user already liked an object 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, query = from activity in Activity,
where: fragment("(?)->>'actor' = ?", activity.data, ^actor), where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
# this is to use the index # this is to use the index
@ -201,7 +201,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def make_create_data(params, additional) do def make_create_data(params, additional) do
published = params.published || make_date() published = params.published || make_date()
activity = %{ %{
"type" => "Create", "type" => "Create",
"to" => params.to |> Enum.uniq, "to" => params.to |> Enum.uniq,
"actor" => params.actor.ap_id, "actor" => params.actor.ap_id,

View File

@ -57,7 +57,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
Enum.join([text | attachment_text], "<br>") Enum.join([text | attachment_text], "<br>")
end end
def format_input(text, mentions, tags) do def format_input(text, mentions, _tags) do
Phoenix.HTML.html_escape(text) Phoenix.HTML.html_escape(text)
|> elem(1) |> elem(1)
|> Formatter.linkify |> Formatter.linkify

View File

@ -71,7 +71,7 @@ defmodule Pleroma.Web.Federator do
end end
end end
def handle(type, payload) do def handle(type, _) do
Logger.debug(fn -> "Unknown task: #{type}" end) Logger.debug(fn -> "Unknown task: #{type}" end)
{:error, "Don't know what do do with this"} {:error, "Don't know what do do with this"}
end end
@ -101,14 +101,14 @@ defmodule Pleroma.Web.Federator do
{:noreply, {running_jobs, queue}} {:noreply, {running_jobs, queue}}
end 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 def handle_info({:DOWN, ref, :process, _pid, _reason}, {running_jobs, queue}) do
running_jobs = :sets.del_element(ref, running_jobs) running_jobs = :sets.del_element(ref, running_jobs)
{running_jobs, queue} = maybe_start_job(running_jobs, queue) {running_jobs, queue} = maybe_start_job(running_jobs, queue)
{:noreply, {running_jobs, queue}} {:noreply, {running_jobs, queue}}
end end
def handle_cast(m, state) do
IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}")
{:noreply, state}
end
end end

View File

@ -4,12 +4,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web alias Pleroma.Web
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView} alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView}
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.{CommonAPI, OStatus} alias Pleroma.Web.{CommonAPI, OStatus}
alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Pleroma.Web.OAuth.{Authorization, Token, App}
alias Comeonin.Pbkdf2 alias Comeonin.Pbkdf2
import Ecto.Query import Ecto.Query
import Logger require Logger
def create_app(conn, params) do def create_app(conn, params) do
with cs <- App.register_changeset(%App{}, params) |> IO.inspect, with cs <- App.register_changeset(%App{}, params) |> IO.inspect,
@ -75,7 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
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}) account = AccountView.render("account.json", %{user: user})
json(conn, account) json(conn, account)
end end
@ -207,7 +206,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
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 params = params
|> Map.put("in_reply_to_status_id", params["in_reply_to_id"]) |> Map.put("in_reply_to_status_id", params["in_reply_to_id"])
@ -293,7 +292,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
render conn, AccountView, "relationships.json", %{user: user, targets: targets} render conn, AccountView, "relationships.json", %{user: user, targets: targets}
end 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 with {:ok, object} <- ActivityPub.upload(file) do
data = object.data data = object.data
|> Map.put("id", object.id) |> Map.put("id", object.id)
@ -303,7 +302,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
def favourited_by(conn, %{"id" => id}) do 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, q = from u in User,
where: u.ap_id in ^likes where: u.ap_id in ^likes
users = Repo.all(q) users = Repo.all(q)
@ -356,10 +355,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
with %User{} = followed <- Repo.get(User, id), with %User{} = followed <- Repo.get(User, id),
{:ok, follower} <- User.follow(follower, followed), {: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} render conn, AccountView, "relationship.json", %{user: follower, target: followed}
else else
{:error, message} = err -> {:error, message} ->
conn conn
|> put_resp_content_type("application/json") |> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message})) |> send_resp(403, Poison.encode!(%{"error" => message}))
@ -369,10 +368,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
with %User{} = followed <- Repo.get_by(User, nickname: uri), with %User{} = followed <- Repo.get_by(User, nickname: uri),
{:ok, follower} <- User.follow(follower, followed), {: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} render conn, AccountView, "account.json", %{user: followed}
else else
{:error, message} = err -> {:error, message} ->
conn conn
|> put_resp_content_type("application/json") |> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message})) |> send_resp(403, Poison.encode!(%{"error" => message}))
@ -397,7 +396,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
{:ok, blocker} <- User.block(blocker, blocked) do {:ok, blocker} <- User.block(blocker, blocked) do
render conn, AccountView, "relationship.json", %{user: blocker, target: blocked} render conn, AccountView, "relationship.json", %{user: blocker, target: blocked}
else else
{:error, message} = err -> {:error, message} ->
conn conn
|> put_resp_content_type("application/json") |> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message})) |> send_resp(403, Poison.encode!(%{"error" => message}))
@ -409,7 +408,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
{:ok, blocker} <- User.unblock(blocker, blocked) do {:ok, blocker} <- User.unblock(blocker, blocked) do
render conn, AccountView, "relationship.json", %{user: blocker, target: blocked} render conn, AccountView, "relationship.json", %{user: blocker, target: blocked}
else else
{:error, message} = err -> {:error, message} ->
conn conn
|> put_resp_content_type("application/json") |> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message})) |> send_resp(403, Poison.encode!(%{"error" => message}))
@ -459,7 +458,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
json(conn, res) json(conn, res)
end end
def favourites(%{assigns: %{user: user}} = conn, params) do def favourites(%{assigns: %{user: user}} = conn, _) do
params = conn params = conn
|> Map.put("type", "Create") |> Map.put("type", "Create")
|> Map.put("favorited_by", user.ap_id) |> Map.put("favorited_by", user.ap_id)
@ -556,7 +555,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
end end
def login(conn, params) do def login(conn, _) do
conn conn
|> render(MastodonView, "login.html") |> render(MastodonView, "login.html")
end end

View File

@ -22,9 +22,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
end end
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 IO.inspect message
#| :ok #| :ok
#| state #| state
@ -34,7 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
{:text, message} {:text, message}
end end
def handle(:closed, reason, %{socket: socket}) do def handle(:closed, _, %{socket: socket}) do
topic = socket.assigns[:topic] topic = socket.assigns[:topic]
Pleroma.Web.Streamer.remove_socket(topic, socket) Pleroma.Web.Streamer.remove_socket(topic, socket)
end end

View File

@ -4,7 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.CommonAPI.Utils 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 defp image_url(_), do: nil
def render("accounts.json", %{users: users} = opts) do def render("accounts.json", %{users: users} = opts) do

View File

@ -108,7 +108,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
updated_at = activity.data["published"] updated_at = activity.data["published"]
inserted_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: [] author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
mentions = activity.data["to"] |> get_mentions mentions = activity.data["to"] |> get_mentions
@ -136,7 +136,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
updated_at = activity.data["published"] updated_at = activity.data["published"]
inserted_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: [] 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"]) retweeted_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
@ -233,6 +233,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
] ++ author ] ++ author
end end
def to_simple_form(_, _, _), do: nil
def wrap_with_entry(simple_form) do def wrap_with_entry(simple_form) do
[{ [{
:entry, [ :entry, [
@ -244,6 +246,4 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
], simple_form ], simple_form
}] }]
end end
def to_simple_form(_, _, _), do: nil
end end

View File

@ -2,7 +2,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter} 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 most_recent_update = (List.first(activities) || user).updated_at
|> NaiveDateTime.to_iso8601 |> NaiveDateTime.to_iso8601

View File

@ -1,10 +1,10 @@
defmodule Pleroma.Web.OStatus.DeleteHandler do defmodule Pleroma.Web.OStatus.DeleteHandler do
require Logger require Logger
alias Pleroma.Web.{XML, OStatus} alias Pleroma.Web.XML
alias Pleroma.{Activity, Object, Repo} alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub 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), with id <- XML.string_from_xpath("//id", entry),
object when not is_nil(object) <- Object.get_by_ap_id(id), object when not is_nil(object) <- Object.get_by_ap_id(id),
{:ok, delete} <- ActivityPub.delete(object, false) do {:ok, delete} <- ActivityPub.delete(object, false) do

View File

@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus do
alias Pleroma.{Repo, User, Web, Object, Activity} alias Pleroma.{Repo, User, Web, Object, Activity}
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.{WebFinger, Websub}
alias Pleroma.Web.OStatus.{FollowHandler, NoteHandler, DeleteHandler} alias Pleroma.Web.OStatus.{FollowHandler, NoteHandler, DeleteHandler}
@ -112,7 +111,7 @@ defmodule Pleroma.Web.OStatus do
with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry), 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 %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
{:ok, activity} {:ok, activity}
else e -> else _ ->
Logger.debug("Couldn't get, will try to fetch") 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), 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 {:ok, [favorited_activity]} <- fetch_activity_from_url(href) do
@ -191,7 +190,7 @@ defmodule Pleroma.Web.OStatus do
false <- new_data == old_data do false <- new_data == old_data do
change = Ecto.Changeset.change(user, new_data) change = Ecto.Changeset.change(user, new_data)
Repo.update(change) Repo.update(change)
else e -> else _ ->
{:ok, user} {:ok, user}
end end
end end

View File

@ -46,7 +46,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
with [decoded | _] <- Pleroma.Web.Salmon.decode(body), with [decoded | _] <- Pleroma.Web.Salmon.decode(body),
doc <- XML.parse_document(decoded), doc <- XML.parse_document(decoded),
uri when not is_nil(uri) <- XML.string_from_xpath("/entry/author[1]/uri", doc), 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, magic_key} <- Pleroma.Web.Salmon.fetch_magic_key(body),
{:ok, doc} <- Pleroma.Web.Salmon.decode_and_validate(magic_key, body) do {:ok, doc} <- Pleroma.Web.Salmon.decode_and_validate(magic_key, body) do
{:ok, doc} {:ok, doc}
@ -54,7 +54,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
end end
end end
def salmon_incoming(conn, params) do def salmon_incoming(conn, _) do
{:ok, body, _conn} = read_body(conn) {:ok, body, _conn} = read_body(conn)
{:ok, doc} = decode_or_retry(body) {:ok, doc} = decode_or_retry(body)

View File

@ -1,7 +1,6 @@
defmodule Pleroma.Web.Streamer do defmodule Pleroma.Web.Streamer do
use GenServer use GenServer
require Logger require Logger
import Plug.Conn
alias Pleroma.{User, Notification} alias Pleroma.{User, Notification}
def start_link do def start_link do
@ -38,17 +37,6 @@ defmodule Pleroma.Web.Streamer do
{:noreply, topics} {:noreply, topics}
end 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 def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item}, topics) do
topic = "user:#{item.user_id}" topic = "user:#{item.user_id}"
Enum.each(topics[topic] || [], fn (socket) -> Enum.each(topics[topic] || [], fn (socket) ->
@ -80,11 +68,6 @@ defmodule Pleroma.Web.Streamer do
{:noreply, topics} {:noreply, topics}
end 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 def handle_cast(%{action: :add, topic: topic, socket: socket}, sockets) do
topic = internal_topic(topic, socket) topic = internal_topic(topic, socket)
sockets_for_topic = sockets[topic] || [] sockets_for_topic = sockets[topic] || []
@ -109,4 +92,21 @@ defmodule Pleroma.Web.Streamer do
IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}")
{:noreply, state} {:noreply, state}
end 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 end

View File

@ -97,7 +97,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
} }
end 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 created_at = created_at |> Utils.date_to_asctime
%{ %{

View File

@ -4,12 +4,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.{OStatus, CommonAPI} alias Pleroma.Web.{OStatus, CommonAPI}
alias Pleroma.Formatter
import Ecto.Query import Ecto.Query
@httpoison Application.get_env(:pleroma, :httpoison) @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) CommonAPI.post(user, data)
end end
@ -216,7 +215,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
end end
end end
defp parse_int(string, default \\ nil) defp parse_int(string, default)
defp parse_int(string, default) when is_binary(string) do defp parse_int(string, default) when is_binary(string) do
with {n, _} <- Integer.parse(string) do with {n, _} <- Integer.parse(string) do
n n

View File

@ -3,7 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.{Repo, Activity, User, Object} alias Pleroma.{Repo, Activity, User}
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Ecto.Changeset alias Ecto.Changeset
@ -13,7 +13,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
render(conn, UserView, "show.json", %{user: user}) render(conn, UserView, "show.json", %{user: user})
end 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), with media_ids <- extract_media_ids(status_data),
{:ok, activity} <- TwitterAPI.create_status(user, Map.put(status_data, "media_ids", media_ids)) do {:ok, activity} <- TwitterAPI.create_status(user, Map.put(status_data, "media_ids", media_ids)) do
conn conn
@ -215,8 +215,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}), with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}),
new_info <- Map.put(user.info, "banner", object.data), new_info <- Map.put(user.info, "banner", object.data),
change <- User.info_changeset(user, %{info: new_info}), change <- User.info_changeset(user, %{info: new_info}),
{:ok, user} <- Repo.update(change) do {:ok, _user} <- Repo.update(change) do
%{"url" => [ %{ "href" => href } | t ]} = object.data %{"url" => [ %{ "href" => href } | _ ]} = object.data
response = %{ url: href } |> Poison.encode! response = %{ url: href } |> Poison.encode!
conn conn
|> json_reply(200, response) |> json_reply(200, response)
@ -227,8 +227,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
with {:ok, object} <- ActivityPub.upload(params), with {:ok, object} <- ActivityPub.upload(params),
new_info <- Map.put(user.info, "background", object.data), new_info <- Map.put(user.info, "background", object.data),
change <- User.info_changeset(user, %{info: new_info}), change <- User.info_changeset(user, %{info: new_info}),
{:ok, user} <- Repo.update(change) do {:ok, _user} <- Repo.update(change) do
%{"url" => [ %{ "href" => href } | t ]} = object.data %{"url" => [ %{ "href" => href } | _ ]} = object.data
response = %{ url: href } |> Poison.encode! response = %{ url: href } |> Poison.encode!
conn conn
|> json_reply(200, response) |> json_reply(200, response)
@ -254,7 +254,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
mrn <- max(id, user.info["most_recent_notification"] || 0), mrn <- max(id, user.info["most_recent_notification"] || 0),
updated_info <- Map.put(info, "most_recent_notification", mrn), updated_info <- Map.put(info, "most_recent_notification", mrn),
changeset <- User.info_changeset(user, %{info: updated_info}), changeset <- User.info_changeset(user, %{info: updated_info}),
{:ok, user} <- Repo.update(changeset) do {:ok, _user} <- Repo.update(changeset) do
conn conn
|> json_reply(200, Poison.encode!(mrn)) |> json_reply(200, Poison.encode!(mrn))
else else
@ -311,7 +311,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end end
end end
def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do def search(%{assigns: %{user: user}} = conn, %{"q" => _query} = params) do
conn conn
|> json(TwitterAPI.search(user, params)) |> json(TwitterAPI.search(user, params))
end end

View File

@ -11,9 +11,6 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user) render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
end end
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
defp image_url(_), do: nil
def render("user.json", %{user: user = %User{}} = assigns) do def render("user.json", %{user: user = %User{}} = assigns) do
image = User.avatar_url(user) image = User.avatar_url(user)
{following, follows_you, statusnet_blocking} = if assigns[:for] do {following, follows_you, statusnet_blocking} = if assigns[:for] do
@ -63,4 +60,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"screen_name" => nickname "screen_name" => nickname
} }
end end
defp image_url(%{"url" => [ %{ "href" => href } | _ ]}), do: href
defp image_url(_), do: nil
end end

View File

@ -89,7 +89,7 @@ defmodule Pleroma.Web.WebFinger 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 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) get_template_from_xml(body)
else else
e -> _ ->
with {:ok, %{body: body}} <- @httpoison.get("https://#{domain}/.well-known/host-meta", []) do with {:ok, %{body: body}} <- @httpoison.get("https://#{domain}/.well-known/host-meta", []) do
get_template_from_xml(body) get_template_from_xml(body)
else else

View File

@ -1,7 +1,7 @@
defmodule Pleroma.Web.XML do defmodule Pleroma.Web.XML do
require Logger require Logger
def string_from_xpath(xpath, :error), do: nil def string_from_xpath(_, :error), do: nil
def string_from_xpath(xpath, doc) do def string_from_xpath(xpath, doc) do
{:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc) {:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc)
@ -20,7 +20,7 @@ defmodule Pleroma.Web.XML do
doc doc
catch catch
:exit, error -> :exit, _error ->
Logger.debug("Couldn't parse xml: #{inspect(text)}") Logger.debug("Couldn't parse xml: #{inspect(text)}")
:error :error
end end

View File

@ -61,7 +61,7 @@ defmodule Phoenix.Transports.WebSocket.Raw do
end end
end end
def ws_info({op, data} = tuple, state) do def ws_info({_,_} = tuple, state) do
{:reply, tuple, state} {:reply, tuple, state}
end end

View File

@ -37,6 +37,6 @@ defmodule Pleroma.XmlBuilder do
"#{attribute}=\"#{value}\"" "#{attribute}=\"#{value}\""
end |> Enum.join(" ") end |> Enum.join(" ")
[tag, attributes_string] |> Enum.join(" ") |> String.strip [tag, attributes_string] |> Enum.join(" ") |> String.trim
end end
end end