logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/
commit: c06fcc7f5ded25968138a7170414ab1c17477ad9
parent d41e2fbaafdd00cf72c1383c6d6aaefbec350b4b
Author: nicole mikołajczyk <me@mkljczk.pl>
Date:   Tue, 16 Dec 2025 23:49:01 +0100

Merge branch 'order-favourites-reblogs' into 'develop'

Order favourites and reblogs list from newest to oldest

See merge request pleroma/pleroma!4399

Diffstat:

Achangelog.d/order-favourites-reblogs.change1+
Mlib/pleroma/web/mastodon_api/controllers/status_controller.ex2++
Mtest/pleroma/web/mastodon_api/controllers/status_controller_test.exs21++++++++++++++++-----
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 oldest diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -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))) 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", %{