2019-09-30 14:10:54 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-02-26 17:13:53 +01:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-09-30 14:10:54 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
2019-09-30 09:28:12 +02:00
|
|
|
import Pleroma.Web.ControllerHelper,
|
2020-04-01 18:49:09 +02:00
|
|
|
only: [
|
|
|
|
add_link_headers: 2,
|
|
|
|
truthy_param?: 1,
|
|
|
|
assign_account_by_id: 2,
|
|
|
|
json_response: 3,
|
|
|
|
skip_relationships?: 1
|
|
|
|
]
|
2019-09-30 14:10:54 +02:00
|
|
|
|
2020-04-24 15:52:38 +02:00
|
|
|
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
|
2019-10-02 19:42:40 +02:00
|
|
|
alias Pleroma.Plugs.OAuthScopesPlug
|
2019-09-30 11:08:29 +02:00
|
|
|
alias Pleroma.Plugs.RateLimiter
|
2019-09-30 14:10:54 +02:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
2019-09-30 11:08:29 +02:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-09-30 14:10:54 +02:00
|
|
|
alias Pleroma.Web.MastodonAPI.ListView
|
2019-09-30 11:08:29 +02:00
|
|
|
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
2020-04-06 09:20:44 +02:00
|
|
|
alias Pleroma.Web.MastodonAPI.MastodonAPIController
|
2019-09-30 11:08:29 +02:00
|
|
|
alias Pleroma.Web.MastodonAPI.StatusView
|
|
|
|
alias Pleroma.Web.OAuth.Token
|
|
|
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
2019-09-30 14:10:54 +02:00
|
|
|
|
2020-04-27 18:46:52 +02:00
|
|
|
plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError)
|
|
|
|
|
2020-04-24 15:52:38 +02:00
|
|
|
plug(:skip_plug, [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :create)
|
2020-04-21 15:29:19 +02:00
|
|
|
|
2020-04-24 15:52:38 +02:00
|
|
|
plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action in [:show, :statuses])
|
2020-04-06 09:20:44 +02:00
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{fallback: :proceed_unauthenticated, scopes: ["read:accounts"]}
|
2020-04-24 15:52:38 +02:00
|
|
|
when action in [:show, :followers, :following]
|
2020-04-21 15:29:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{fallback: :proceed_unauthenticated, scopes: ["read:statuses"]}
|
|
|
|
when action == :statuses
|
2019-10-02 19:42:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["read:accounts"]}
|
2020-04-24 15:52:38 +02:00
|
|
|
when action in [:verify_credentials, :endorsements, :identity_proofs]
|
2019-10-02 19:42:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :update_credentials)
|
|
|
|
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action == :lists)
|
|
|
|
|
2019-10-06 16:12:17 +02:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["follow", "read:blocks"]} when action == :blocks
|
|
|
|
)
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["follow", "write:blocks"]} when action in [:block, :unblock]
|
|
|
|
)
|
|
|
|
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["read:follows"]} when action == :relationships)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2020-04-21 15:29:19 +02:00
|
|
|
%{scopes: ["follow", "write:follows"]} when action in [:follow_by_uri, :follow, :unfollow]
|
2019-10-02 19:42:40 +02:00
|
|
|
)
|
|
|
|
|
2019-10-06 16:12:17 +02:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["follow", "read:mutes"]} when action == :mutes)
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["follow", "write:mutes"]} when action in [:mute, :unmute])
|
|
|
|
|
2020-03-25 07:04:00 +01:00
|
|
|
@relationship_actions [:follow, :unfollow]
|
2019-09-30 11:08:29 +02:00
|
|
|
@needs_account ~W(followers following lists follow unfollow mute unmute block unblock)a
|
2019-09-30 14:10:54 +02:00
|
|
|
|
2020-03-25 07:04:00 +01:00
|
|
|
plug(
|
|
|
|
RateLimiter,
|
|
|
|
[name: :relation_id_action, params: ["id", "uri"]] when action in @relationship_actions
|
|
|
|
)
|
|
|
|
|
|
|
|
plug(RateLimiter, [name: :relations_actions] when action in @relationship_actions)
|
2019-11-11 13:13:06 +01:00
|
|
|
plug(RateLimiter, [name: :app_account_creation] when action == :create)
|
2019-09-30 11:08:29 +02:00
|
|
|
plug(:assign_account_by_id when action in @needs_account)
|
2019-09-30 14:10:54 +02:00
|
|
|
|
|
|
|
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
|
|
|
|
2020-04-03 20:45:08 +02:00
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.AccountOperation
|
|
|
|
|
2019-09-30 11:08:29 +02:00
|
|
|
@doc "POST /api/v1/accounts"
|
2020-04-03 20:45:08 +02:00
|
|
|
def create(%{assigns: %{app: app}, body_params: params} = conn, _params) do
|
2020-02-26 17:13:53 +01:00
|
|
|
with :ok <- validate_email_param(params),
|
2020-04-29 18:48:08 +02:00
|
|
|
:ok <- TwitterAPI.validate_captcha(app, params),
|
2020-02-26 17:13:53 +01:00
|
|
|
{:ok, user} <- TwitterAPI.register_user(params, need_confirmation: true),
|
2019-09-30 11:08:29 +02:00
|
|
|
{:ok, token} <- Token.create_token(app, user, %{scopes: app.scopes}) do
|
|
|
|
json(conn, %{
|
|
|
|
token_type: "Bearer",
|
|
|
|
access_token: token.token,
|
|
|
|
scope: app.scopes,
|
|
|
|
created_at: Token.Utils.format_created_at(token)
|
|
|
|
})
|
|
|
|
else
|
2020-04-29 18:48:08 +02:00
|
|
|
{:error, error} -> json_response(conn, :bad_request, %{error: error})
|
2019-09-30 11:08:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(%{assigns: %{app: _app}} = conn, _) do
|
|
|
|
render_error(conn, :bad_request, "Missing parameters")
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, _) do
|
|
|
|
render_error(conn, :forbidden, "Invalid credentials")
|
|
|
|
end
|
|
|
|
|
2020-04-29 18:48:08 +02:00
|
|
|
defp validate_email_param(%{email: email}) when not is_nil(email), do: :ok
|
2020-02-26 17:13:53 +01:00
|
|
|
|
|
|
|
defp validate_email_param(_) do
|
|
|
|
case Pleroma.Config.get([:instance, :account_activation_required]) do
|
2020-04-29 18:48:08 +02:00
|
|
|
true -> {:error, dgettext("errors", "Missing parameter: %{name}", name: "email")}
|
2020-02-26 17:13:53 +01:00
|
|
|
_ -> :ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 11:08:29 +02:00
|
|
|
@doc "GET /api/v1/accounts/verify_credentials"
|
|
|
|
def verify_credentials(%{assigns: %{user: user}} = conn, _) do
|
|
|
|
chat_token = Phoenix.Token.sign(conn, "user socket", user.id)
|
|
|
|
|
|
|
|
render(conn, "show.json",
|
|
|
|
user: user,
|
|
|
|
for: user,
|
|
|
|
with_pleroma_settings: true,
|
|
|
|
with_chat_token: chat_token
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-09-30 10:47:01 +02:00
|
|
|
@doc "PATCH /api/v1/accounts/update_credentials"
|
2020-04-07 12:53:12 +02:00
|
|
|
def update_credentials(%{assigns: %{user: original_user}, body_params: params} = conn, _params) do
|
2019-09-30 10:47:01 +02:00
|
|
|
user = original_user
|
|
|
|
|
2020-04-07 12:53:12 +02:00
|
|
|
params =
|
|
|
|
params
|
|
|
|
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
|
|
|
|
|> Enum.into(%{})
|
|
|
|
|
2019-10-16 20:59:21 +02:00
|
|
|
user_params =
|
2019-09-30 10:47:01 +02:00
|
|
|
[
|
|
|
|
:no_rich_text,
|
|
|
|
:locked,
|
|
|
|
:hide_followers_count,
|
|
|
|
:hide_follows_count,
|
|
|
|
:hide_followers,
|
|
|
|
:hide_follows,
|
|
|
|
:hide_favorites,
|
|
|
|
:show_role,
|
|
|
|
:skip_thread_containment,
|
2019-11-12 12:36:50 +01:00
|
|
|
:allow_following_move,
|
2019-09-30 10:47:01 +02:00
|
|
|
:discoverable
|
|
|
|
]
|
|
|
|
|> Enum.reduce(%{}, fn key, acc ->
|
2020-04-07 12:53:12 +02:00
|
|
|
add_if_present(acc, params, key, key, &{:ok, truthy_param?(&1)})
|
2019-09-30 10:47:01 +02:00
|
|
|
end)
|
2020-04-07 12:53:12 +02:00
|
|
|
|> add_if_present(params, :display_name, :name)
|
|
|
|
|> add_if_present(params, :note, :bio)
|
|
|
|
|> add_if_present(params, :avatar, :avatar)
|
|
|
|
|> add_if_present(params, :header, :banner)
|
|
|
|
|> add_if_present(params, :pleroma_background_image, :background)
|
2020-01-31 19:07:46 +01:00
|
|
|
|> add_if_present(
|
|
|
|
params,
|
2020-04-07 12:53:12 +02:00
|
|
|
:fields_attributes,
|
2020-01-31 19:07:46 +01:00
|
|
|
:raw_fields,
|
|
|
|
&{:ok, normalize_fields_attributes(&1)}
|
|
|
|
)
|
2020-04-07 12:53:12 +02:00
|
|
|
|> add_if_present(params, :pleroma_settings_store, :pleroma_settings_store)
|
|
|
|
|> add_if_present(params, :default_scope, :default_scope)
|
|
|
|
|> add_if_present(params, :actor_type, :actor_type)
|
2019-10-16 20:59:21 +02:00
|
|
|
|
2019-10-20 12:42:42 +02:00
|
|
|
changeset = User.update_changeset(user, user_params)
|
2019-09-30 10:47:01 +02:00
|
|
|
|
|
|
|
with {:ok, user} <- User.update_and_set_cache(changeset) do
|
|
|
|
render(conn, "show.json", user: user, for: user, with_pleroma_settings: true)
|
|
|
|
else
|
|
|
|
_e -> render_error(conn, :forbidden, "Invalid request")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp add_if_present(map, params, params_field, map_field, value_function \\ &{:ok, &1}) do
|
|
|
|
with true <- Map.has_key?(params, params_field),
|
2020-04-07 12:53:12 +02:00
|
|
|
{:ok, new_value} <- value_function.(Map.get(params, params_field)) do
|
2019-09-30 10:47:01 +02:00
|
|
|
Map.put(map, map_field, new_value)
|
|
|
|
else
|
|
|
|
_ -> map
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 18:39:22 +02:00
|
|
|
defp normalize_fields_attributes(fields) do
|
|
|
|
if Enum.all?(fields, &is_tuple/1) do
|
|
|
|
Enum.map(fields, fn {_, v} -> v end)
|
|
|
|
else
|
2020-04-07 12:53:12 +02:00
|
|
|
Enum.map(fields, fn
|
2020-04-27 20:55:05 +02:00
|
|
|
%{} = field -> %{"name" => field.name, "value" => field.value}
|
|
|
|
field -> field
|
2020-04-07 12:53:12 +02:00
|
|
|
end)
|
2019-09-30 18:39:22 +02:00
|
|
|
end
|
2019-09-30 10:47:01 +02:00
|
|
|
end
|
|
|
|
|
2019-09-30 11:08:29 +02:00
|
|
|
@doc "GET /api/v1/accounts/relationships"
|
2020-04-07 16:29:05 +02:00
|
|
|
def relationships(%{assigns: %{user: user}} = conn, %{id: id}) do
|
2019-09-30 11:08:29 +02:00
|
|
|
targets = User.get_all_by_ids(List.wrap(id))
|
|
|
|
|
|
|
|
render(conn, "relationships.json", user: user, targets: targets)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array.
|
|
|
|
def relationships(%{assigns: %{user: _user}} = conn, _), do: json(conn, [])
|
|
|
|
|
2019-09-30 14:10:54 +02:00
|
|
|
@doc "GET /api/v1/accounts/:id"
|
2020-04-07 16:53:12 +02:00
|
|
|
def show(%{assigns: %{user: for_user}} = conn, %{id: nickname_or_id}) do
|
2019-09-30 14:10:54 +02:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname_or_id, for: for_user),
|
2019-11-04 18:44:24 +01:00
|
|
|
true <- User.visible_for?(user, for_user) do
|
2019-09-30 14:10:54 +02:00
|
|
|
render(conn, "show.json", user: user, for: for_user)
|
|
|
|
else
|
|
|
|
_e -> render_error(conn, :not_found, "Can't find user")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "GET /api/v1/accounts/:id/statuses"
|
|
|
|
def statuses(%{assigns: %{user: reading_user}} = conn, params) do
|
2020-04-08 20:33:25 +02:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname_or_id(params.id, for: reading_user),
|
2020-03-20 11:04:37 +01:00
|
|
|
true <- User.visible_for?(user, reading_user) do
|
2019-12-06 14:25:13 +01:00
|
|
|
params =
|
|
|
|
params
|
2020-04-08 20:33:25 +02:00
|
|
|
|> Map.delete(:tagged)
|
|
|
|
|> Enum.filter(&(not is_nil(&1)))
|
|
|
|
|> Map.new(fn {key, value} -> {to_string(key), value} end)
|
|
|
|
|> Map.put("tag", params[:tagged])
|
2019-12-06 14:25:13 +01:00
|
|
|
|
2019-09-30 14:10:54 +02:00
|
|
|
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> add_link_headers(activities)
|
|
|
|
|> put_view(StatusView)
|
2020-04-01 18:49:09 +02:00
|
|
|
|> render("index.json",
|
|
|
|
activities: activities,
|
|
|
|
for: reading_user,
|
|
|
|
as: :activity,
|
|
|
|
skip_relationships: skip_relationships?(params)
|
|
|
|
)
|
2020-03-20 11:04:37 +01:00
|
|
|
else
|
|
|
|
_e -> render_error(conn, :not_found, "Can't find user")
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "GET /api/v1/accounts/:id/followers"
|
|
|
|
def followers(%{assigns: %{user: for_user, account: user}} = conn, params) do
|
2020-04-08 21:16:20 +02:00
|
|
|
params =
|
|
|
|
params
|
|
|
|
|> Enum.map(fn {key, value} -> {to_string(key), value} end)
|
|
|
|
|> Enum.into(%{})
|
|
|
|
|
2019-09-30 14:10:54 +02:00
|
|
|
followers =
|
|
|
|
cond do
|
|
|
|
for_user && user.id == for_user.id -> MastodonAPI.get_followers(user, params)
|
2019-10-16 20:59:21 +02:00
|
|
|
user.hide_followers -> []
|
2019-09-30 14:10:54 +02:00
|
|
|
true -> MastodonAPI.get_followers(user, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> add_link_headers(followers)
|
|
|
|
|> render("index.json", for: for_user, users: followers, as: :user)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "GET /api/v1/accounts/:id/following"
|
|
|
|
def following(%{assigns: %{user: for_user, account: user}} = conn, params) do
|
2020-04-08 21:38:07 +02:00
|
|
|
params =
|
|
|
|
params
|
|
|
|
|> Enum.map(fn {key, value} -> {to_string(key), value} end)
|
|
|
|
|> Enum.into(%{})
|
|
|
|
|
2019-09-30 14:10:54 +02:00
|
|
|
followers =
|
|
|
|
cond do
|
|
|
|
for_user && user.id == for_user.id -> MastodonAPI.get_friends(user, params)
|
2019-10-16 20:59:21 +02:00
|
|
|
user.hide_follows -> []
|
2019-09-30 14:10:54 +02:00
|
|
|
true -> MastodonAPI.get_friends(user, params)
|
|
|
|
end
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> add_link_headers(followers)
|
|
|
|
|> render("index.json", for: for_user, users: followers, as: :user)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "GET /api/v1/accounts/:id/lists"
|
|
|
|
def lists(%{assigns: %{user: user, account: account}} = conn, _params) do
|
|
|
|
lists = Pleroma.List.get_lists_account_belongs(user, account)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_view(ListView)
|
|
|
|
|> render("index.json", lists: lists)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/follow"
|
|
|
|
def follow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
2020-04-22 15:04:26 +02:00
|
|
|
{:error, "Can not follow yourself"}
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
|
2020-04-09 13:25:24 +02:00
|
|
|
def follow(%{assigns: %{user: follower, account: followed}} = conn, params) do
|
|
|
|
with {:ok, follower} <- MastodonAPI.follow(follower, followed, params) do
|
2019-09-30 14:10:54 +02:00
|
|
|
render(conn, "relationship.json", user: follower, target: followed)
|
|
|
|
else
|
2019-09-30 09:28:12 +02:00
|
|
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 09:28:12 +02:00
|
|
|
@doc "POST /api/v1/accounts/:id/unfollow"
|
2019-09-30 14:10:54 +02:00
|
|
|
def unfollow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
2020-04-22 15:04:26 +02:00
|
|
|
{:error, "Can not unfollow yourself"}
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
|
|
|
|
with {:ok, follower} <- CommonAPI.unfollow(follower, followed) do
|
|
|
|
render(conn, "relationship.json", user: follower, target: followed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/mute"
|
2020-04-09 16:28:14 +02:00
|
|
|
def mute(%{assigns: %{user: muter, account: muted}, body_params: params} = conn, _params) do
|
|
|
|
with {:ok, _user_relationships} <- User.mute(muter, muted, params.notifications) do
|
2019-09-30 14:10:54 +02:00
|
|
|
render(conn, "relationship.json", user: muter, target: muted)
|
|
|
|
else
|
2019-09-30 09:28:12 +02:00
|
|
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/unmute"
|
|
|
|
def unmute(%{assigns: %{user: muter, account: muted}} = conn, _params) do
|
2019-11-19 21:22:10 +01:00
|
|
|
with {:ok, _user_relationships} <- User.unmute(muter, muted) do
|
2019-09-30 14:10:54 +02:00
|
|
|
render(conn, "relationship.json", user: muter, target: muted)
|
|
|
|
else
|
2019-09-30 09:28:12 +02:00
|
|
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/block"
|
|
|
|
def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
|
2019-11-10 14:30:21 +01:00
|
|
|
with {:ok, _user_block} <- User.block(blocker, blocked),
|
2019-09-30 14:10:54 +02:00
|
|
|
{:ok, _activity} <- ActivityPub.block(blocker, blocked) do
|
|
|
|
render(conn, "relationship.json", user: blocker, target: blocked)
|
|
|
|
else
|
2019-09-30 09:28:12 +02:00
|
|
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/unblock"
|
|
|
|
def unblock(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
|
2019-11-10 14:30:21 +01:00
|
|
|
with {:ok, _user_block} <- User.unblock(blocker, blocked),
|
2019-09-30 14:10:54 +02:00
|
|
|
{:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do
|
|
|
|
render(conn, "relationship.json", user: blocker, target: blocked)
|
|
|
|
else
|
2019-09-30 09:28:12 +02:00
|
|
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
2019-10-02 19:42:40 +02:00
|
|
|
|
2019-10-01 12:15:58 +02:00
|
|
|
@doc "POST /api/v1/follows"
|
2020-04-28 18:56:20 +02:00
|
|
|
def follow_by_uri(%{body_params: %{uri: uri}} = conn, _) do
|
2020-04-22 15:04:26 +02:00
|
|
|
case User.get_cached_by_nickname(uri) do
|
|
|
|
%User{} = user ->
|
|
|
|
conn
|
|
|
|
|> assign(:account, user)
|
|
|
|
|> follow(%{})
|
|
|
|
|
|
|
|
nil ->
|
|
|
|
{:error, :not_found}
|
2019-10-01 12:15:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "GET /api/v1/mutes"
|
|
|
|
def mutes(%{assigns: %{user: user}} = conn, _) do
|
2019-11-19 21:22:10 +01:00
|
|
|
users = User.muted_users(user, _restrict_deactivated = true)
|
|
|
|
render(conn, "index.json", users: users, for: user, as: :user)
|
2019-10-01 12:15:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc "GET /api/v1/blocks"
|
|
|
|
def blocks(%{assigns: %{user: user}} = conn, _) do
|
2019-11-19 21:22:10 +01:00
|
|
|
users = User.blocked_users(user, _restrict_deactivated = true)
|
|
|
|
render(conn, "index.json", users: users, for: user, as: :user)
|
2019-10-01 12:15:58 +02:00
|
|
|
end
|
2019-10-06 10:43:49 +02:00
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
@doc "GET /api/v1/endorsements"
|
2020-04-06 09:20:44 +02:00
|
|
|
def endorsements(conn, params), do: MastodonAPIController.empty_array(conn, params)
|
|
|
|
|
|
|
|
@doc "GET /api/v1/identity_proofs"
|
|
|
|
def identity_proofs(conn, params), do: MastodonAPIController.empty_array(conn, params)
|
2019-09-30 14:10:54 +02:00
|
|
|
end
|