Allow to get group followed events after a certain date
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
4923c52f3b
commit
b12cea5ead
|
@ -633,11 +633,17 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
|||
}}
|
||||
end
|
||||
|
||||
def user_followed_group_events(%User{id: user_id}, %{page: page, limit: limit}, %{
|
||||
def user_followed_group_events(%User{id: user_id}, %{page: page, limit: limit} = args, %{
|
||||
context: %{current_user: %User{id: logged_in_user_id}}
|
||||
})
|
||||
when user_id == logged_in_user_id do
|
||||
activities = FollowedGroupActivity.user_followed_group_events(user_id, page, limit)
|
||||
activities =
|
||||
FollowedGroupActivity.user_followed_group_events(
|
||||
user_id,
|
||||
Map.get(args, :after_datetime),
|
||||
page,
|
||||
limit
|
||||
)
|
||||
|
||||
activities = %Page{
|
||||
activities
|
||||
|
|
|
@ -117,6 +117,10 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
|||
description: "The limit of follow group events per page"
|
||||
)
|
||||
|
||||
arg(:after_datetime, :datetime,
|
||||
description: "Filter follow group events by event start datetime"
|
||||
)
|
||||
|
||||
resolve(&User.user_followed_group_events/3)
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,13 @@ defmodule Mobilizon.FollowedGroupActivity do
|
|||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Storage.Page
|
||||
|
||||
def user_followed_group_events(user_id, page \\ nil, limit \\ nil) do
|
||||
@spec user_followed_group_events(
|
||||
integer() | String.t(),
|
||||
DateTime.t() | nil,
|
||||
integer() | nil,
|
||||
integer() | nil
|
||||
) :: Page.t(Event.t())
|
||||
def user_followed_group_events(user_id, after_datetime, page \\ nil, limit \\ nil) do
|
||||
Event
|
||||
|> distinct([e], e.id)
|
||||
|> join(:left, [e], p in Participant, on: e.id == p.event_id)
|
||||
|
@ -19,10 +25,10 @@ defmodule Mobilizon.FollowedGroupActivity do
|
|||
|> join(:inner, [_e, _p, pa, _g, f, m], a in Actor,
|
||||
on: a.id == f.actor_id or a.id == m.actor_id
|
||||
)
|
||||
|> add_after_datetime_filter(after_datetime)
|
||||
|> where(
|
||||
[e, p, pa, _g, f, m, a],
|
||||
e.begins_on > ^DateTime.utc_now() and
|
||||
(f.approved or m.role in ^[:member, :moderator, :administrator, :creator]) and
|
||||
[_e, p, pa, _g, f, m, a],
|
||||
(f.approved or m.role in ^[:member, :moderator, :administrator, :creator]) and
|
||||
a.user_id == ^user_id and
|
||||
pa.user_id != ^user_id
|
||||
)
|
||||
|
@ -40,4 +46,11 @@ defmodule Mobilizon.FollowedGroupActivity do
|
|||
])
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@spec add_after_datetime_filter(Ecto.Query.t(), DateTime.t() | nil) :: Ecto.Query.t()
|
||||
defp add_after_datetime_filter(query, nil),
|
||||
do: where(query, [e], e.begins_on > ^DateTime.utc_now())
|
||||
|
||||
defp add_after_datetime_filter(query, %DateTime{} = datetime),
|
||||
do: where(query, [e], e.begins_on > ^datetime)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue