Refactor Mobilizon.Federation.ActivityPub and add typespecs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
|
||||
alias Mobilizon.{Actors, Todos}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.Actions
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Todos.{Todo, TodoList}
|
||||
import Mobilizon.Web.Gettext
|
||||
@@ -17,6 +17,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
|
||||
Returns only if actor requesting is a member of the group
|
||||
"""
|
||||
@spec find_todo_lists_for_group(Actor.t(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Page.t(TodoList.t())}
|
||||
def find_todo_lists_for_group(
|
||||
%Actor{id: group_id} = group,
|
||||
_args,
|
||||
@@ -39,6 +41,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
{:ok, %Page{total: 0, elements: []}}
|
||||
end
|
||||
|
||||
@spec find_todo_lists_for_group(TodoList.t(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Page.t(Todo.t())} | {:error, String.t()}
|
||||
def find_todos_for_todo_list(
|
||||
%TodoList{actor_id: group_id} = todo_list,
|
||||
_args,
|
||||
@@ -55,6 +59,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
end
|
||||
end
|
||||
|
||||
@spec get_todo_list(any(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, TodoList.t()} | {:error, String.t()}
|
||||
def get_todo_list(
|
||||
_parent,
|
||||
%{id: todo_list_id},
|
||||
@@ -78,6 +84,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
end
|
||||
end
|
||||
|
||||
@spec create_todo_list(any(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, TodoList.t()} | {:error, String.t()}
|
||||
def create_todo_list(
|
||||
_parent,
|
||||
%{group_id: group_id} = args,
|
||||
@@ -87,7 +95,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
) do
|
||||
with {:member, true} <- {:member, Actors.is_member?(actor_id, group_id)},
|
||||
{:ok, _, %TodoList{} = todo_list} <-
|
||||
ActivityPub.create(:todo_list, Map.put(args, :actor_id, group_id), true, %{}) do
|
||||
Actions.Create.create(
|
||||
:todo_list,
|
||||
Map.put(args, :actor_id, group_id),
|
||||
true,
|
||||
%{}
|
||||
) do
|
||||
{:ok, todo_list}
|
||||
else
|
||||
{:actor, nil} ->
|
||||
@@ -110,7 +123,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
# {:todo_list, Todos.get_todo_list(todo_list_id)},
|
||||
# {:member, true} <- {:member, Actors.is_member?(actor_id, group_id)},
|
||||
# {:ok, _, %TodoList{} = todo} <-
|
||||
# ActivityPub.update_todo_list(todo_list, actor, true, %{}) do
|
||||
# Actions.Update.update_todo_list(todo_list, actor, true, %{}) do
|
||||
# {:ok, todo}
|
||||
# else
|
||||
# {:todo_list, _} ->
|
||||
@@ -133,7 +146,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
# {:todo_list, Todos.get_todo_list(todo_list_id)},
|
||||
# {:member, true} <- {:member, Actors.is_member?(actor_id, group_id)},
|
||||
# {:ok, _, %TodoList{} = todo} <-
|
||||
# ActivityPub.delete_todo_list(todo_list, actor, true, %{}) do
|
||||
# Actions.Delete.delete_todo_list(todo_list, actor, true, %{}) do
|
||||
# {:ok, todo}
|
||||
# else
|
||||
# {:todo_list, _} ->
|
||||
@@ -144,6 +157,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
# end
|
||||
# end
|
||||
|
||||
@spec get_todo(any(), map(), Absinthe.Resolution.t()) :: {:ok, Todo.t()} | {:error, String.t()}
|
||||
def get_todo(
|
||||
_parent,
|
||||
%{id: todo_id},
|
||||
@@ -169,6 +183,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
end
|
||||
end
|
||||
|
||||
@spec create_todo(any(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Todo.t()} | {:error, String.t()}
|
||||
def create_todo(
|
||||
_parent,
|
||||
%{todo_list_id: todo_list_id} = args,
|
||||
@@ -180,7 +196,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
{:todo_list, Todos.get_todo_list(todo_list_id)},
|
||||
{:member, true} <- {:member, Actors.is_member?(actor_id, group_id)},
|
||||
{:ok, _, %Todo{} = todo} <-
|
||||
ActivityPub.create(:todo, Map.put(args, :creator_id, actor_id), true, %{}) do
|
||||
Actions.Create.create(
|
||||
:todo,
|
||||
Map.put(args, :creator_id, actor_id),
|
||||
true,
|
||||
%{}
|
||||
) do
|
||||
{:ok, todo}
|
||||
else
|
||||
{:actor, nil} ->
|
||||
@@ -194,6 +215,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
end
|
||||
end
|
||||
|
||||
@spec update_todo(any(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Todo.t()} | {:error, String.t()}
|
||||
def update_todo(
|
||||
_parent,
|
||||
%{id: todo_id} = args,
|
||||
@@ -207,7 +230,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
{:todo_list, Todos.get_todo_list(todo_list_id)},
|
||||
{:member, true} <- {:member, Actors.is_member?(actor_id, group_id)},
|
||||
{:ok, _, %Todo{} = todo} <-
|
||||
ActivityPub.update(todo, args, true, %{}) do
|
||||
Actions.Update.update(todo, args, true, %{}) do
|
||||
{:ok, todo}
|
||||
else
|
||||
{:actor, nil} ->
|
||||
@@ -238,7 +261,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Todos do
|
||||
# {:todo_list, Todos.get_todo_list(todo_list_id)},
|
||||
# {:member, true} <- {:member, Actors.is_member?(actor_id, group_id)},
|
||||
# {:ok, _, %Todo{} = todo} <-
|
||||
# ActivityPub.delete_todo(todo, actor, true, %{}) do
|
||||
# Actions.Delete.delete_todo(todo, actor, true, %{}) do
|
||||
# {:ok, todo}
|
||||
# else
|
||||
# {:todo_list, _} ->
|
||||
|
||||
Reference in New Issue
Block a user