2018-12-03 10:58:57 +00:00
|
|
|
defmodule MobilizonWeb.Resolvers.Person do
|
2018-11-06 09:30:27 +00:00
|
|
|
alias Mobilizon.Actors
|
2018-11-07 15:09:28 +00:00
|
|
|
alias Mobilizon.Service.ActivityPub
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-12-03 10:58:57 +00:00
|
|
|
@deprecated "Use find_person/3 or find_group/3 instead"
|
2018-11-06 09:30:27 +00:00
|
|
|
def find_actor(_parent, %{preferred_username: name}, _resolution) do
|
2018-11-07 15:09:28 +00:00
|
|
|
case ActivityPub.find_or_make_actor_from_nickname(name) do
|
|
|
|
{:ok, actor} ->
|
2018-11-06 09:30:27 +00:00
|
|
|
{:ok, actor}
|
2018-11-07 15:09:42 +00:00
|
|
|
|
2018-11-07 15:09:28 +00:00
|
|
|
_ ->
|
|
|
|
{:error, "Actor with name #{name} not found"}
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
@doc """
|
|
|
|
Find a person
|
|
|
|
"""
|
|
|
|
def find_person(_parent, %{preferred_username: name}, _resolution) do
|
|
|
|
case ActivityPub.find_or_make_person_from_nickname(name) do
|
|
|
|
{:ok, actor} ->
|
|
|
|
{:ok, actor}
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{:error, "Person with name #{name} not found"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-06 09:30:27 +00:00
|
|
|
@doc """
|
|
|
|
Returns the current actor for the currently logged-in user
|
|
|
|
"""
|
2018-11-23 14:03:53 +00:00
|
|
|
def get_current_person(_parent, _args, %{context: %{current_user: user}}) do
|
2018-11-06 09:30:27 +00:00
|
|
|
{:ok, Actors.get_actor_for_user(user)}
|
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
def get_current_person(_parent, _args, _resolution) do
|
|
|
|
{:error, "You need to be logged-in to view current person"}
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
end
|