[GraphQL] Expose events from followed/member group activity
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
88b078ebce
commit
23fddaedf1
@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
|
||||
import Mobilizon.Users.Guards
|
||||
|
||||
alias Mobilizon.{Actors, Admin, Config, Events, Users}
|
||||
alias Mobilizon.{Actors, Admin, Config, Events, FollowedGroupActivity, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Relay}
|
||||
alias Mobilizon.Service.Auth.Authenticator
|
||||
@ -633,6 +633,23 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||
}}
|
||||
end
|
||||
|
||||
def user_followed_group_events(%User{id: user_id}, %{page: page, limit: limit}, %{
|
||||
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 = %Page{
|
||||
activities
|
||||
| elements:
|
||||
Enum.map(activities.elements, fn [event, group, profile] ->
|
||||
%{group: group, profile: profile, event: event}
|
||||
end)
|
||||
}
|
||||
|
||||
{:ok, activities}
|
||||
end
|
||||
|
||||
@spec update_user_login_information(User.t(), map()) ::
|
||||
{:ok, User.t()} | {:error, Ecto.Changeset.t()}
|
||||
defp update_user_login_information(
|
||||
|
@ -49,6 +49,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
||||
import_types(Schema.StatisticsType)
|
||||
import_types(Schema.Users.PushSubscription)
|
||||
import_types(Schema.Users.ActivitySetting)
|
||||
import_types(Schema.FollowedGroupActivityType)
|
||||
|
||||
@desc "A struct containing the id of the deleted object"
|
||||
object :deleted_object do
|
||||
@ -157,7 +158,6 @@ defmodule Mobilizon.GraphQL.Schema do
|
||||
import_fields(:resource_queries)
|
||||
import_fields(:post_queries)
|
||||
import_fields(:statistics_queries)
|
||||
# import_fields(:push_queries)
|
||||
end
|
||||
|
||||
@desc """
|
||||
|
20
lib/graphql/schema/followed_group_activity.ex
Normal file
20
lib/graphql/schema/followed_group_activity.ex
Normal file
@ -0,0 +1,20 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.FollowedGroupActivityType do
|
||||
@moduledoc """
|
||||
Schema representation for a follow activity
|
||||
"""
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
@desc "A paginated list of follow group events"
|
||||
object :paginated_followed_group_events do
|
||||
field(:elements, list_of(:followed_group_event), description: "A list of follow group events")
|
||||
field(:total, :integer, description: "The total number of follow group events in the list")
|
||||
end
|
||||
|
||||
@desc "A follow group event"
|
||||
object :followed_group_event do
|
||||
field(:user, :user)
|
||||
field(:profile, :person)
|
||||
field(:group, :group)
|
||||
field(:event, :event)
|
||||
end
|
||||
end
|
@ -104,6 +104,22 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||
resolve(&User.user_drafted_events/3)
|
||||
end
|
||||
|
||||
field(:followed_group_events, :paginated_followed_group_events,
|
||||
description: "The suggested events from the groups this user follows"
|
||||
) do
|
||||
arg(:page, :integer,
|
||||
default_value: 1,
|
||||
description: "The page in the follow group events list"
|
||||
)
|
||||
|
||||
arg(:limit, :integer,
|
||||
default_value: 10,
|
||||
description: "The limit of follow group events per page"
|
||||
)
|
||||
|
||||
resolve(&User.user_followed_group_events/3)
|
||||
end
|
||||
|
||||
field(:settings, :user_settings, description: "The list of settings for this user") do
|
||||
resolve(&User.user_settings/3)
|
||||
end
|
||||
|
43
lib/mobilizon/followed_group_activity.ex
Normal file
43
lib/mobilizon/followed_group_activity.ex
Normal file
@ -0,0 +1,43 @@
|
||||
defmodule Mobilizon.FollowedGroupActivity do
|
||||
@moduledoc """
|
||||
Provide recent elements from groups that profiles follow
|
||||
"""
|
||||
|
||||
import Ecto.Query
|
||||
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Storage.Page
|
||||
|
||||
def user_followed_group_events(user_id, page \\ nil, limit \\ nil) do
|
||||
Event
|
||||
|> distinct([e], e.id)
|
||||
|> join(:left, [e], p in Participant, on: e.id == p.event_id)
|
||||
|> join(:inner, [_e, p], pa in Actor, on: p.actor_id == pa.id)
|
||||
|> join(:inner, [e], g in Actor, on: e.attributed_to_id == g.id)
|
||||
|> join(:left, [_e, _p, _pa, g], f in Follower, on: g.id == f.target_actor_id)
|
||||
|> join(:left, [_e, _p, _pa, g], m in Member, on: g.id == m.parent_id)
|
||||
|> join(:inner, [_e, _p, pa, _g, f, m], a in Actor,
|
||||
on: a.id == f.actor_id or a.id == m.actor_id
|
||||
)
|
||||
|> 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
|
||||
a.user_id == ^user_id and
|
||||
pa.user_id != ^user_id
|
||||
)
|
||||
|> preload([
|
||||
:organizer_actor,
|
||||
:attributed_to,
|
||||
:tags,
|
||||
:physical_address,
|
||||
:picture
|
||||
])
|
||||
|> select([e, g, _f, _m, a], [
|
||||
e,
|
||||
g,
|
||||
a
|
||||
])
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user