Order favourites and reblogs list from newest to oldest
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
ca03d94f52
commit
21f486c872
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
|
||||||
|
|
@ -488,6 +488,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
||||||
users =
|
users =
|
||||||
User
|
User
|
||||||
|> Ecto.Query.where([u], u.ap_id in ^likes)
|
|> Ecto.Query.where([u], u.ap_id in ^likes)
|
||||||
|
|> Ecto.Query.order_by([u], fragment("array_position(?, ?)", ^likes, u.ap_id))
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.filter(&(not User.blocks?(user, &1)))
|
|> Enum.filter(&(not User.blocks?(user, &1)))
|
||||||
|
|
||||||
|
|
@ -523,6 +524,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
||||||
users =
|
users =
|
||||||
User
|
User
|
||||||
|> Ecto.Query.where([u], u.ap_id in ^announces)
|
|> Ecto.Query.where([u], u.ap_id in ^announces)
|
||||||
|
|> Ecto.Query.order_by([u], fragment("array_position(?, ?)", ^announces, u.ap_id))
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.filter(&(not User.blocks?(user, &1)))
|
|> Enum.filter(&(not User.blocks?(user, &1)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1867,18 +1867,29 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
%{activity: activity}
|
%{activity: activity}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns users who have favorited the status", %{conn: conn, activity: activity} do
|
test "returns users who have favorited the status ordered from newest to oldest", %{
|
||||||
other_user = insert(:user)
|
conn: conn,
|
||||||
{:ok, _} = CommonAPI.favorite(activity.id, other_user)
|
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 =
|
response =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
|
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
|
||||||
|> json_response_and_validate_schema(:ok)
|
|> 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
|
end
|
||||||
|
|
||||||
test "returns empty array when status has not been favorited yet", %{
|
test "returns empty array when status has not been favorited yet", %{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue