1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-30 20:06:07 +00:00
mobilizon/lib/graphql/resolvers/activity.ex
Thomas Citharel b5d9b82bdd
Refactor Mobilizon.Federation.ActivityPub and add typespecs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-09-29 16:31:11 +02:00

42 lines
1.3 KiB
Elixir

defmodule Mobilizon.GraphQL.Resolvers.Activity do
@moduledoc """
Handles the activity-related GraphQL calls.
"""
import Mobilizon.Users.Guards
alias Mobilizon.{Activities, Actors}
alias Mobilizon.Activities.Activity
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.Activity.Utils
alias Mobilizon.Storage.Page
alias Mobilizon.Users.User
require Logger
@spec group_activity(Actor.t(), map(), Absinthe.Resolution.t()) ::
{:ok, Page.t(Activity.t())} | {:error, :unauthorized | :unauthenticated}
def group_activity(%Actor{type: :Group, id: group_id}, %{page: page, limit: limit} = args, %{
context: %{current_user: %User{role: role}, current_actor: %Actor{id: actor_id}}
}) do
if Actors.is_member?(actor_id, group_id) or is_moderator(role) do
%Page{total: total, elements: elements} =
Activities.list_group_activities_for_member(
group_id,
actor_id,
[type: Map.get(args, :type), author: Map.get(args, :author)],
page,
limit
)
elements = Enum.map(elements, &Utils.transform_activity/1)
{:ok, %Page{total: total, elements: elements}}
else
{:error, :unauthorized}
end
end
def group_activity(_, _, _) do
{:error, :unauthenticated}
end
end