commit: 21f486c8725ddf625e39c7592eff8bd7b23785bc parent ca03d94f52f3494c767267a31840224b23c7b1b4 Author: nicole mikołajczyk <git@mkljczk.pl> Date: Sun, 30 Nov 2025 00:05:24 +0100 Order favourites and reblogs list from newest to oldest Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>Diffstat:
3 files changed, 19 insertions(+), 5 deletions(-)diff --git a/changelog.d/order-favourites-reblogs.change b/changelog.d/order-favourites-reblogs.change@@ -0,0 +1 @@ +Order favourites and reblogs list from newest to oldestdiff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex@@ -488,6 +488,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))) @@ -523,6 +524,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)))diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs@@ -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", %{