summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--docs/API/differences_in_mastoapi_responses.md2
-rw-r--r--docs/API/pleroma_api.md14
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex4
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex4
-rw-r--r--lib/pleroma/web/router.ex6
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs8
-rw-r--r--test/web/pleroma_api/controllers/pleroma_api_controller_test.exs24
8 files changed, 32 insertions, 31 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1c6ad4fd9..150fd27cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<details>
<summary>API Changes</summary>
+- **Breaking** EmojiReactions: Change endpoints and responses to align with Mastodon
- **Breaking** Admin API: `PATCH /api/pleroma/admin/users/:nickname/force_password_reset` is now `PATCH /api/pleroma/admin/users/force_password_reset` (accepts `nicknames` array in the request body)
- **Breaking:** Admin API: Return link alongside with token on password reset
- **Breaking:** Admin API: `PUT /api/pleroma/admin/reports/:id` is now `PATCH /api/pleroma/admin/reports`, see admin_api.md for details
diff --git a/docs/API/differences_in_mastoapi_responses.md b/docs/API/differences_in_mastoapi_responses.md
index ebf842b7e..06de90f71 100644
--- a/docs/API/differences_in_mastoapi_responses.md
+++ b/docs/API/differences_in_mastoapi_responses.md
@@ -29,7 +29,7 @@ Has these additional fields under the `pleroma` object:
- `spoiler_text`: a map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
- `expires_at`: a datetime (iso8601) that states when the post will expire (be deleted automatically), or empty if the post won't expire
- `thread_muted`: true if the thread the post belongs to is muted
-- `emoji_reactions`: A list with emoji / reaction maps. The format is `{emoji: "☕", count: 1, reacted: true}`. Contains no information about the reacting users, for that use the `emoji_reactions_by` endpoint.
+- `emoji_reactions`: A list with emoji / reaction maps. The format is `{name: "☕", count: 1, me: true}`. Contains no information about the reacting users, for that use the `/statuses/:id/reactions` endpoint.
## Attachments
diff --git a/docs/API/pleroma_api.md b/docs/API/pleroma_api.md
index c7125c1cd..07e0af5e5 100644
--- a/docs/API/pleroma_api.md
+++ b/docs/API/pleroma_api.md
@@ -432,21 +432,21 @@ The status posting endpoint takes an additional parameter, `in_reply_to_conversa
Emoji reactions work a lot like favourites do. They make it possible to react to a post with a single emoji character.
-## `POST /api/v1/pleroma/statuses/:id/react_with_emoji`
+## `PUT /api/v1/pleroma/statuses/:id/reactions/:emoji`
### React to a post with a unicode emoji
-* Method: `POST`
+* Method: `PUT`
* Authentication: required
* Params: `emoji`: A single character unicode emoji
* Response: JSON, the status.
-## `POST /api/v1/pleroma/statuses/:id/unreact_with_emoji`
+## `DELETE /api/v1/pleroma/statuses/:id/reactions/:emoji`
### Remove a reaction to a post with a unicode emoji
-* Method: `POST`
+* Method: `DELETE`
* Authentication: required
* Params: `emoji`: A single character unicode emoji
* Response: JSON, the status.
-## `GET /api/v1/pleroma/statuses/:id/emoji_reactions_by`
+## `GET /api/v1/pleroma/statuses/:id/reactions`
### Get an object of emoji to account mappings with accounts that reacted to the post
* Method: `GET`
* Authentication: optional
@@ -455,7 +455,7 @@ Emoji reactions work a lot like favourites do. They make it possible to react to
* Example Response:
```json
[
- {"emoji": "😀", "count": 2, "reacted": true, "accounts": [{"id" => "xyz.."...}, {"id" => "zyx..."}]},
- {"emoji": "☕", "count": 1, "reacted": false, "accounts": [{"id" => "abc..."}]}
+ {"name": "😀", "count": 2, "me": true, "accounts": [{"id" => "xyz.."...}, {"id" => "zyx..."}]},
+ {"name": "☕", "count": 1, "me": false, "accounts": [{"id" => "abc..."}]}
]
```
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 6cb158bbf..e1e92034f 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -242,9 +242,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
with %{data: %{"reactions" => emoji_reactions}} <- object do
Enum.map(emoji_reactions, fn [emoji, users] ->
%{
- emoji: emoji,
+ name: emoji,
count: length(users),
- reacted: !!(opts[:for] && opts[:for].ap_id in users)
+ me: !!(opts[:for] && opts[:for].ap_id in users)
}
end)
else
diff --git a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
index d76e39795..108e48438 100644
--- a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
@@ -53,10 +53,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
|> Enum.filter(& &1)
%{
- emoji: emoji,
+ name: emoji,
count: length(users),
accounts: AccountView.render("index.json", %{users: users, for: user, as: :user}),
- reacted: !!(user && user.ap_id in user_ap_ids)
+ me: !!(user && user.ap_id in user_ap_ids)
}
end)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index e86bc3cc3..897215698 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -271,7 +271,7 @@ defmodule Pleroma.Web.Router do
scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
pipe_through(:api)
- get("/statuses/:id/emoji_reactions_by", PleromaAPIController, :emoji_reactions_by)
+ get("/statuses/:id/reactions", PleromaAPIController, :emoji_reactions_by)
end
scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
@@ -287,8 +287,8 @@ defmodule Pleroma.Web.Router do
pipe_through(:authenticated_api)
patch("/conversations/:id", PleromaAPIController, :update_conversation)
- post("/statuses/:id/react_with_emoji", PleromaAPIController, :react_with_emoji)
- post("/statuses/:id/unreact_with_emoji", PleromaAPIController, :unreact_with_emoji)
+ put("/statuses/:id/reactions/:emoji", PleromaAPIController, :react_with_emoji)
+ delete("/statuses/:id/reactions/:emoji", PleromaAPIController, :unreact_with_emoji)
post("/notifications/read", PleromaAPIController, :read_notification)
patch("/accounts/update_avatar", AccountController, :update_avatar)
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index fc110417c..ba58e48e8 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -37,15 +37,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("show.json", activity: activity)
assert status[:pleroma][:emoji_reactions] == [
- %{emoji: "☕", count: 2, reacted: false},
- %{emoji: "🍵", count: 1, reacted: false}
+ %{name: "☕", count: 2, me: false},
+ %{name: "🍵", count: 1, me: false}
]
status = StatusView.render("show.json", activity: activity, for: user)
assert status[:pleroma][:emoji_reactions] == [
- %{emoji: "☕", count: 2, reacted: true},
- %{emoji: "🍵", count: 1, reacted: false}
+ %{name: "☕", count: 2, me: true},
+ %{name: "🍵", count: 1, me: false}
]
end
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
index be5007de5..36868db38 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -14,7 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
import Pleroma.Factory
- test "POST /api/v1/pleroma/statuses/:id/react_with_emoji", %{conn: conn} do
+ test "PUT /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -24,18 +24,19 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
conn
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"]))
- |> post("/api/v1/pleroma/statuses/#{activity.id}/react_with_emoji", %{"emoji" => "☕"})
+ |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/☕")
|> json_response(200)
+ # We return the status, but this our implementation detail.
assert %{"id" => id} = result
assert to_string(activity.id) == id
assert result["pleroma"]["emoji_reactions"] == [
- %{"emoji" => "☕", "count" => 1, "reacted" => true}
+ %{"name" => "☕", "count" => 1, "me" => true}
]
end
- test "POST /api/v1/pleroma/statuses/:id/unreact_with_emoji", %{conn: conn} do
+ test "DELETE /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -46,7 +47,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
conn
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"]))
- |> post("/api/v1/pleroma/statuses/#{activity.id}/unreact_with_emoji", %{"emoji" => "☕"})
+ |> delete("/api/v1/pleroma/statuses/#{activity.id}/reactions/☕")
assert %{"id" => id} = json_response(result, 200)
assert to_string(activity.id) == id
@@ -56,7 +57,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
assert object.data["reaction_count"] == 0
end
- test "GET /api/v1/pleroma/statuses/:id/emoji_reactions_by", %{conn: conn} do
+ test "GET /api/v1/pleroma/statuses/:id/reactions", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
doomed_user = insert(:user)
@@ -65,7 +66,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
result =
conn
- |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
+ |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|> json_response(200)
assert result == []
@@ -77,11 +78,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
result =
conn
- |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
+ |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|> json_response(200)
- [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user], "reacted" => false}] =
- result
+ [%{"name" => "🎅", "count" => 1, "accounts" => [represented_user], "me" => false}] = result
assert represented_user["id"] == other_user.id
@@ -89,10 +89,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
conn
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:statuses"]))
- |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
+ |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|> json_response(200)
- assert [%{"emoji" => "🎅", "count" => 1, "accounts" => [_represented_user], "reacted" => true}] =
+ assert [%{"name" => "🎅", "count" => 1, "accounts" => [_represented_user], "me" => true}] =
result
end