From c05fe4da0a9ad119891d2fc6cf82ea3beb59fec7 Mon Sep 17 00:00:00 2001 From: Sadposter Date: Sat, 6 Apr 2019 16:20:06 +0100 Subject: [PATCH] Document subscription endpoints, fix typos Also adds a quick error case on the subscription endpoints to avoid 500s --- docs/api/pleroma_api.md | 52 ++++++++++++++++++- .../mastodon_api/mastodon_api_controller.ex | 20 ++++--- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/docs/api/pleroma_api.md b/docs/api/pleroma_api.md index 478c9d874..410f2a955 100644 --- a/docs/api/pleroma_api.md +++ b/docs/api/pleroma_api.md @@ -52,7 +52,7 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi * `confirm` * `captcha_solution`: optional, contains provider-specific captcha solution, * `captcha_token`: optional, contains provider-specific captcha token - * `token`: invite token required when the registerations aren't public. + * `token`: invite token required when the registrations aren't public. * Response: JSON. Returns a user object on success, otherwise returns `{"error": "error_msg"}` * Example response: ``` @@ -114,5 +114,53 @@ See [Admin-API](Admin-API.md) * Method `POST` * Authentication: required * Params: - * `id`: notifications's id + * `id`: notification's id * Response: JSON. Returns `{"status": "success"}` if the reading was successful, otherwise returns `{"error": "error_msg"}` + +## `/api/v1/pleroma/accounts/:id/subscribe` +### Subscribe to receive notifications for all statuses posted by a user +* Method `POST` +* Authentication: required +* Params: + * `id`: account id to subscribe to +* Response: JSON, returns a mastodon relationship object on success, otherwise returns `{"error": "error_msg"}` +* Example response: +```json +{ + id: "abcdefg", + following: true, + followed_by: false, + blocking: false, + muting: false, + muting_notifications: false, + subscribing: true, + requested: false, + domain_blocking: false, + showing_reblogs: true, + endorsed: false +} +``` + +## `/api/v1/pleroma/accounts/:id/unsubscribe` +### Unsubscribe to stop receiving notifications from user statuses +* Method `POST` +* Authentication: required +* Params: + * `id`: account id to unsubscribe from +* Response: JSON, returns a mastodon relationship object on success, otherwise returns `{"error": "error_msg"}` +* Example response: +```json +{ + id: "abcdefg", + following: true, + followed_by: false, + blocking: false, + muting: false, + muting_notifications: false, + subscribing: false, + requested: false, + domain_blocking: false, + showing_reblogs: true, + endorsed: false +} +``` diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e848895f1..a7c9c4735 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -864,22 +864,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def subscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with %User{} = subscription_target <- User.get_by_id(id) do - {:ok, subscription_target} = User.subscribe(user, subscription_target) - + with %User{} = subscription_target <- User.get_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_by_id(id) do - {:ok, subscription_target} = User.unsubscribe(user, subscription_target) - + with %User{} = subscription_target <- User.get_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