diff options
author | Alex S <alex.strizhakov@gmail.com> | 2019-04-10 18:06:54 +0700 |
---|---|---|
committer | Alex S <alex.strizhakov@gmail.com> | 2019-04-10 18:06:54 +0700 |
commit | fe511a6c653f24f95dd3bed5941724e3d0155f3a (patch) | |
tree | 097971af07615b9965329d595d9cb00c7ef2d5f8 /lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | |
parent | fe13a1d78c13fbe7b3027d442a6f6906440e5acc (diff) | |
parent | e5d553aa45ffa218b0695d7976f012bfc1dcbafe (diff) | |
download | pleroma-fe511a6c653f24f95dd3bed5941724e3d0155f3a.tar.gz |
Merge branch 'develop' into feature/788-separate-email-addresses
Diffstat (limited to 'lib/pleroma/web/mastodon_api/mastodon_api_controller.ex')
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5462ce8be..ed082abdf 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -931,6 +931,34 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, %{}) end + def subscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with %User{} = subscription_target <- User.get_cached_by_id(id), + {:ok, subscription_target} = User.subscribe(user, subscription_target) do + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: user, target: subscription_target}) + else + {:error, message} -> + conn + |> put_resp_content_type("application/json") + |> send_resp(403, Jason.encode!(%{"error" => message})) + end + end + + def unsubscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with %User{} = subscription_target <- User.get_cached_by_id(id), + {:ok, subscription_target} = User.unsubscribe(user, subscription_target) do + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: user, target: subscription_target}) + else + {:error, message} -> + conn + |> put_resp_content_type("application/json") + |> send_resp(403, Jason.encode!(%{"error" => message})) + end + end + def status_search(user, query) do fetched = if Regex.match?(~r/https?:/, query) do |