aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-01-24 11:31:24 +0000
committerrinpatch <rinpatch@sdf.org>2020-01-24 11:31:24 +0000
commitecff8e92ffca75465ef607d10ad59b318e68cd1e (patch)
treeb61db46c679b776c4e77df3d0d34aad0c8bacf3f
parenta182d400d7d5aa414240b156965533c0e9b222d0 (diff)
parent9a994878f18e4804f83d36eed441de53b53b3691 (diff)
downloadpleroma-ecff8e92ffca75465ef607d10ad59b318e68cd1e.tar.gz
Merge branch 'emoji-reaction-api-change-2' into 'develop'
Emoji reaction api change 2 See merge request pleroma/pleroma!2140
-rw-r--r--CHANGELOG.md1
-rw-r--r--docs/API/differences_in_mastoapi_responses.md2
-rw-r--r--docs/API/pleroma_api.md4
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex2
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex7
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs5
-rw-r--r--test/web/pleroma_api/controllers/pleroma_api_controller_test.exs2
7 files changed, 16 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 861312e18..ca740792c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -98,6 +98,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: Add `emoji_reactions` property to Statuses
- Mastodon API: Change emoji reaction reply format
- Notifications: Added `pleroma:emoji_reaction` notification type
+- Mastodon API: Change emoji reaction reply format once more
</details>
### Fixed
diff --git a/docs/API/differences_in_mastoapi_responses.md b/docs/API/differences_in_mastoapi_responses.md
index 2236870c7..030660b34 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 count tuples. 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 {emoji: "☕", count: 1}. Contains no information about the reacting users, for that use the `emoji_reactions_by` endpoint.
## Attachments
diff --git a/docs/API/pleroma_api.md b/docs/API/pleroma_api.md
index 9ca8a5af0..9f5cafe5a 100644
--- a/docs/API/pleroma_api.md
+++ b/docs/API/pleroma_api.md
@@ -455,7 +455,7 @@ Emoji reactions work a lot like favourites do. They make it possible to react to
* Example Response:
```json
[
- ["😀", [{"id" => "xyz.."...}, {"id" => "zyx..."}]],
- ["☕", [{"id" => "abc..."}]]
+ {"emoji": "😀", "count": 2, "accounts": [{"id" => "xyz.."...}, {"id" => "zyx..."}]},
+ {"emoji": "☕", "count": 1, "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 64a97896a..e60ef709b 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -256,7 +256,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
emoji_reactions =
with %{data: %{"reactions" => emoji_reactions}} <- object do
Enum.map(emoji_reactions, fn [emoji, users] ->
- [emoji, length(users)]
+ %{emoji: emoji, count: length(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 bb19836ae..cd1c0764f 100644
--- a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
@@ -49,7 +49,12 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
emoji_reactions
|> Enum.map(fn [emoji, users] ->
users = Enum.map(users, &User.get_cached_by_ap_id/1)
- {emoji, AccountView.render("index.json", %{users: users, for: user, as: :user})}
+
+ %{
+ emoji: emoji,
+ count: length(users),
+ accounts: AccountView.render("index.json", %{users: users, for: user, as: :user})
+ }
end)
conn
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 069bb8eac..25777b011 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -36,7 +36,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
activity = Repo.get(Activity, activity.id)
status = StatusView.render("show.json", activity: activity)
- assert status[:pleroma][:emoji_reactions] == [["☕", 2], ["🍵", 1]]
+ assert status[:pleroma][:emoji_reactions] == [
+ %{emoji: "☕", count: 2},
+ %{emoji: "🍵", count: 1}
+ ]
end
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
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 a79ecd05b..3978c2ec5 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -71,7 +71,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
|> json_response(200)
- [["🎅", [represented_user]]] = result
+ [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user]}] = result
assert represented_user["id"] == other_user.id
end