defmodule Pleroma.PasswordResetToken do
use Ecto.Schema
- import Ecto.{Changeset, Query}
+ import Ecto.Changeset
alias Pleroma.{User, PasswordResetToken, Repo}
end
def used_changeset(struct) do
- changeset = struct
+ struct
|> cast(%{}, [])
|> put_change(:used, true)
end
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
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)
end
def change(struct, params \\ %{}) do
- changeset = struct
+ struct
|> cast(params, [:data])
|> validate_required([:data])
|> unique_constraint(:ap_id, name: :objects_unique_apid_index)
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)
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
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]+$/)
|> follow_changeset(%{following: following})
|> Repo.update
- {:ok, followed} = update_follower_count(followed)
+ {:ok, _} = update_follower_count(followed)
follower
end
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
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
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
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
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),
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),
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
@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
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,
Enum.join([text | attachment_text], "<br>")
end
- def format_input(text, mentions, tags) do
+ def format_input(text, mentions, _tags) do
Phoenix.HTML.html_escape(text)
|> elem(1)
|> Formatter.linkify
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
{: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
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,
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
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"])
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)
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)
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}))
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}))
{: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}))
{: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}))
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)
end
end
- def login(conn, params) do
+ def login(conn, _) do
conn
|> render(MastodonView, "login.html")
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
#| :ok
#| state
{: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
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
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
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"])
] ++ author
end
+ def to_simple_form(_, _, _), do: nil
+
def wrap_with_entry(simple_form) do
[{
:entry, [
], simple_form
}]
end
-
- def to_simple_form(_, _, _), do: nil
end
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
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
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}
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
false <- new_data == old_data do
change = Ecto.Changeset.change(user, new_data)
Repo.update(change)
- else e ->
+ else _ ->
{:ok, user}
end
end
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}
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)
defmodule Pleroma.Web.Streamer do
use GenServer
require Logger
- import Plug.Conn
alias Pleroma.{User, Notification}
def start_link 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) ->
{: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] || []
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
}
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
%{
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
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
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
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
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)
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)
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
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
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
"screen_name" => nickname
}
end
+
+ defp image_url(%{"url" => [ %{ "href" => href } | _ ]}), do: href
+ defp image_url(_), do: nil
end
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
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)
doc
catch
- :exit, error ->
+ :exit, _error ->
Logger.debug("Couldn't parse xml: #{inspect(text)}")
:error
end
end
end
- def ws_info({op, data} = tuple, state) do
+ def ws_info({_,_} = tuple, state) do
{:reply, tuple, state}
end
"#{attribute}=\"#{value}\""
end |> Enum.join(" ")
- [tag, attributes_string] |> Enum.join(" ") |> String.strip
+ [tag, attributes_string] |> Enum.join(" ") |> String.trim
end
end