fix(feeds): make sure posts for feeds are ordered by publication date desc
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
e73fd9b370
commit
3c75856149
|
@ -22,11 +22,13 @@ defmodule Mobilizon.Posts do
|
|||
:private
|
||||
])
|
||||
|
||||
@spec list_public_local_posts(integer | nil, integer | nil) :: Page.t(Post.t())
|
||||
def list_public_local_posts(page \\ nil, limit \\ nil) do
|
||||
@spec list_public_local_posts(integer | nil, integer | nil, atom | nil, atom | nil) ::
|
||||
Page.t(Post.t())
|
||||
def list_public_local_posts(page \\ nil, limit \\ nil, sort \\ nil, direction \\ nil) do
|
||||
Post
|
||||
|> filter_public()
|
||||
|> filter_local()
|
||||
|> order_posts(sort, direction)
|
||||
|> preload_post_associations()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
@ -171,4 +173,13 @@ defmodule Mobilizon.Posts do
|
|||
defp preload_post_associations(query, associations \\ @post_preloads) do
|
||||
preload(query, ^associations)
|
||||
end
|
||||
|
||||
@spec order_posts(Ecto.Queryable.t(), atom | nil, atom | nil) :: Ecto.Queryable.t()
|
||||
def order_posts(query, nil, _direction), do: query
|
||||
def order_posts(query, _sort, nil), do: query
|
||||
|
||||
def order_posts(query, sort, direction) do
|
||||
order_by_param = Keyword.new([{direction, sort}])
|
||||
order_by(query, ^order_by_param)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,7 +97,7 @@ defmodule Mobilizon.Service.Export.Common do
|
|||
@spec fetch_instance_public_content(integer()) :: {:ok, list(Event.t()), list(Post.t())}
|
||||
def fetch_instance_public_content(limit) do
|
||||
%Page{elements: events} = Events.list_public_local_events(1, limit, :begins_on, :desc)
|
||||
%Page{elements: posts} = Posts.list_public_local_posts(1, limit)
|
||||
%Page{elements: posts} = Posts.list_public_local_posts(1, limit, :publish_at, :desc)
|
||||
{:ok, events, posts}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue