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 @@ def create_token(%User{} = user) 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 @@ def used_changeset(struct) 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 @@ def dismiss(%{id: user_id} = _user, id) 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 @@ def create(data) 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 @@ def init(options) 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 @@ def remote_user_creation(params) 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 @@ def follow(%User{} = follower, %User{} = followed) 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 @@ def get_or_fetch_by_nickname(nickname) 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 @@ def update_follower_count(%User{} = 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 @@ def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) 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 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil, loca
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 @@ def unlike(%User{} = actor, %Object{} = object) 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 @@ def lazy_put_object_defaults(map) 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 @@ def update_object_in_activities(%{data: %{"id" => id}} = object) 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 @@ def make_unfollow_data(follower, followed, follow_activity) 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 @@ def add_attachments(text, attachments) 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 @@ def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback,
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 @@ def handle_cast({:enqueue, type, payload}, {running_jobs, queue}) 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 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) 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 @@ def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) 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 @@ def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) 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 @@ def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) 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 @@ def following(conn, %{"id" => id}) 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 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) 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 @@ def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) 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 @@ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) 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 @@ def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) d
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 @@ def index(%{assigns: %{user: user}} = conn, _params) 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 @@ def connect(params, socket) 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 @@ def handle(:text, message, state) 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 @@ def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) d
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 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho
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 @@ def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author)
] ++ 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 @@ def wrap_with_entry(simple_form) 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 @@ def get_or_try_fetching(entry) 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 @@ def maybe_update(doc, user) 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 @@ defp decode_or_retry(body) 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 @@ defp decode_or_retry(body) 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 @@ def handle_cast(%{action: :ping}, topics) 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 @@ def handle_cast(%{action: :stream, topic: topic, item: item}, topics) 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 @@ def handle_cast(m, state) 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 @@ def to_map(%Activity{data: %{"type" => "Undo", "published" => created_at, "objec
} }
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 @@ def get_user(user \\ nil, params) 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 @@ def verify_credentials(%{assigns: %{user: user}} = conn, _params) 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 @@ def update_banner(%{assigns: %{user: user}} = conn, params) 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 @@ def update_background(%{assigns: %{user: user}} = conn, params) 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 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
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 @@ def update_profile(%{assigns: %{user: user}} = conn, params) 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 @@ def render("index.json", %{users: users, for: user}) 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 @@ def render("short.json", %{user: %User{
"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 @@ 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 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 @@ def parse_document(text) 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 @@ def ws_handle(op, data, state) 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 @@ defp make_open_tag(tag, attributes) 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