Merge branch 'order-favourites-reblogs' into 'develop'
Order favourites and reblogs list from newest to oldest See merge request pleroma/pleroma!4399
This commit is contained in:
commit
c06fcc7f5d
3 changed files with 19 additions and 5 deletions
1
changelog.d/order-favourites-reblogs.change
Normal file
1
changelog.d/order-favourites-reblogs.change
Normal file
|
|
@ -0,0 +1 @@
|
|||
Order favourites and reblogs list from newest to oldest
|
||||
|
|
@ -490,6 +490,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
|||
users =
|
||||
User
|
||||
|> Ecto.Query.where([u], u.ap_id in ^likes)
|
||||
|> Ecto.Query.order_by([u], fragment("array_position(?, ?)", ^likes, u.ap_id))
|
||||
|> Repo.all()
|
||||
|> Enum.filter(&(not User.blocks?(user, &1)))
|
||||
|
||||
|
|
@ -525,6 +526,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
|||
users =
|
||||
User
|
||||
|> Ecto.Query.where([u], u.ap_id in ^announces)
|
||||
|> Ecto.Query.order_by([u], fragment("array_position(?, ?)", ^announces, u.ap_id))
|
||||
|> Repo.all()
|
||||
|> Enum.filter(&(not User.blocks?(user, &1)))
|
||||
|
||||
|
|
|
|||
|
|
@ -1867,18 +1867,29 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
%{activity: activity}
|
||||
end
|
||||
|
||||
test "returns users who have favorited the status", %{conn: conn, activity: activity} do
|
||||
other_user = insert(:user)
|
||||
{:ok, _} = CommonAPI.favorite(activity.id, other_user)
|
||||
test "returns users who have favorited the status ordered from newest to oldest", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
[other_user_1, other_user_2] = insert_pair(:user)
|
||||
[other_user_3, other_user_4] = insert_pair(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.favorite(activity.id, other_user_1)
|
||||
{:ok, _} = CommonAPI.favorite(activity.id, other_user_3)
|
||||
{:ok, _} = CommonAPI.favorite(activity.id, other_user_2)
|
||||
{:ok, _} = CommonAPI.favorite(activity.id, other_user_4)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
[%{"id" => id}] = response
|
||||
[%{"id" => id1}, %{"id" => id2}, %{"id" => id3}, %{"id" => id4}] = response
|
||||
|
||||
assert id == other_user.id
|
||||
assert id1 == other_user_4.id
|
||||
assert id2 == other_user_2.id
|
||||
assert id3 == other_user_3.id
|
||||
assert id4 == other_user_1.id
|
||||
end
|
||||
|
||||
test "returns empty array when status has not been favorited yet", %{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue