Set correct values in the MastoAPI reblog status view
This commit is contained in:
parent
2d54fdcdfe
commit
375fd21055
4 changed files with 19 additions and 7 deletions
|
@ -73,6 +73,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Mastodon API: Streaming API broadcasting wrong activity id
|
- Mastodon API: Streaming API broadcasting wrong activity id
|
||||||
- Mastodon API: 500 errors when requesting a card for a private conversation
|
- Mastodon API: 500 errors when requesting a card for a private conversation
|
||||||
- Mastodon API: Handling of `reblogs` in `/api/v1/accounts/:id/follow`
|
- Mastodon API: Handling of `reblogs` in `/api/v1/accounts/:id/follow`
|
||||||
|
- Mastodon API: Correct `reblogged`, `favourited`, and `bookmarked` values in the reblog status JSON
|
||||||
|
|
||||||
## [0.9.9999] - 2019-04-05
|
## [0.9.9999] - 2019-04-05
|
||||||
### Security
|
### Security
|
||||||
|
|
|
@ -338,7 +338,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{} = activity <- Activity.get_by_id(id),
|
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
||||||
true <- Visibility.visible_for_user?(activity, user) do
|
true <- Visibility.visible_for_user?(activity, user) do
|
||||||
conn
|
conn
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|
@ -487,7 +487,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def reblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
|
def reblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
|
||||||
with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user) do
|
with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user),
|
||||||
|
%Activity{} = announce <- Activity.normalize(announce.data) do
|
||||||
conn
|
conn
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|> try_render("status.json", %{activity: announce, for: user, as: :activity})
|
|> try_render("status.json", %{activity: announce, for: user, as: :activity})
|
||||||
|
@ -496,7 +497,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
|
|
||||||
def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
|
def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
|
||||||
with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
|
with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
|
||||||
%Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do
|
%Activity{} = activity <- Activity.get_create_by_object_ap_id_with_object(id) do
|
||||||
conn
|
conn
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
||||||
|
|
|
@ -83,6 +83,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
reblogged_activity = Activity.get_create_by_object_ap_id(object)
|
reblogged_activity = Activity.get_create_by_object_ap_id(object)
|
||||||
reblogged = render("status.json", Map.put(opts, :activity, reblogged_activity))
|
reblogged = render("status.json", Map.put(opts, :activity, reblogged_activity))
|
||||||
|
|
||||||
|
activity_object = Object.normalize(activity)
|
||||||
|
favorited = opts[:for] && opts[:for].ap_id in (activity_object.data["likes"] || [])
|
||||||
|
bookmarked = opts[:for] && activity_object.data["id"] in opts[:for].bookmarks
|
||||||
|
|
||||||
mentions =
|
mentions =
|
||||||
activity.recipients
|
activity.recipients
|
||||||
|> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
|
|> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
|
||||||
|
@ -103,8 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
replies_count: 0,
|
replies_count: 0,
|
||||||
favourites_count: 0,
|
favourites_count: 0,
|
||||||
reblogged: reblogged?(reblogged_activity, opts[:for]),
|
reblogged: reblogged?(reblogged_activity, opts[:for]),
|
||||||
favourited: false,
|
favourited: present?(favorited),
|
||||||
bookmarked: false,
|
bookmarked: present?(bookmarked),
|
||||||
muted: false,
|
muted: false,
|
||||||
pinned: pinned?(activity, user),
|
pinned: pinned?(activity, user),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
|
|
|
@ -1021,6 +1021,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
user1 = insert(:user)
|
user1 = insert(:user)
|
||||||
user2 = insert(:user)
|
user2 = insert(:user)
|
||||||
user3 = insert(:user)
|
user3 = insert(:user)
|
||||||
|
CommonAPI.favorite(activity.id, user2)
|
||||||
|
{:ok, user2} = User.bookmark(user2, activity.data["object"]["id"])
|
||||||
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
|
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
|
||||||
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
|
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
|
||||||
|
|
||||||
|
@ -1031,7 +1033,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
|
|
||||||
assert %{
|
assert %{
|
||||||
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
|
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
|
||||||
"reblogged" => false
|
"reblogged" => false,
|
||||||
|
"favourited" => false,
|
||||||
|
"bookmarked" => false
|
||||||
} = json_response(conn_res, 200)
|
} = json_response(conn_res, 200)
|
||||||
|
|
||||||
conn_res =
|
conn_res =
|
||||||
|
@ -1041,7 +1045,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
|
|
||||||
assert %{
|
assert %{
|
||||||
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
|
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
|
||||||
"reblogged" => true
|
"reblogged" => true,
|
||||||
|
"favourited" => true,
|
||||||
|
"bookmarked" => true
|
||||||
} = json_response(conn_res, 200)
|
} = json_response(conn_res, 200)
|
||||||
|
|
||||||
assert to_string(activity.id) == id
|
assert to_string(activity.id) == id
|
||||||
|
|
Loading…
Reference in a new issue