2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.ActorView do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2018-05-18 09:56:21 +02:00
|
|
|
View for Actors
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2018-10-11 17:37:39 +02:00
|
|
|
use MobilizonWeb, :view
|
|
|
|
alias MobilizonWeb.{ActorView, EventView, MemberView}
|
|
|
|
alias Mobilizon.Actors
|
2018-01-09 17:52:26 +01:00
|
|
|
|
2018-05-18 09:56:21 +02:00
|
|
|
def render("index.json", %{actors: actors}) do
|
2018-07-10 10:00:07 +02:00
|
|
|
%{data: render_many(actors, ActorView, "actor_basic.json")}
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
2018-05-18 09:56:21 +02:00
|
|
|
def render("show.json", %{actor: actor}) do
|
|
|
|
%{data: render_one(actor, ActorView, "actor.json")}
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
2018-05-18 09:56:21 +02:00
|
|
|
def render("show_basic.json", %{actor: actor}) do
|
|
|
|
%{data: render_one(actor, ActorView, "actor_basic.json")}
|
2018-01-16 19:45:09 +01:00
|
|
|
end
|
|
|
|
|
2018-07-10 10:00:07 +02:00
|
|
|
def render("actor_basic.json", %{actor: actor}) do
|
2018-07-27 10:45:35 +02:00
|
|
|
%{
|
|
|
|
id: actor.id,
|
2018-05-19 10:19:21 +02:00
|
|
|
username: actor.preferred_username,
|
2018-05-18 09:56:21 +02:00
|
|
|
domain: actor.domain,
|
2018-05-19 10:19:21 +02:00
|
|
|
display_name: actor.name,
|
|
|
|
description: actor.summary,
|
2018-05-30 14:27:21 +02:00
|
|
|
type: actor.type,
|
2018-05-18 09:56:21 +02:00
|
|
|
# public_key: actor.public_key,
|
|
|
|
suspended: actor.suspended,
|
|
|
|
url: actor.url,
|
2018-07-27 10:45:35 +02:00
|
|
|
avatar: actor.avatar_url
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-18 09:56:21 +02:00
|
|
|
def render("actor.json", %{actor: actor}) do
|
2018-07-27 10:45:35 +02:00
|
|
|
output = %{
|
|
|
|
id: actor.id,
|
2018-05-19 10:19:21 +02:00
|
|
|
username: actor.preferred_username,
|
2018-05-18 09:56:21 +02:00
|
|
|
domain: actor.domain,
|
2018-05-19 10:19:21 +02:00
|
|
|
display_name: actor.name,
|
|
|
|
description: actor.summary,
|
2018-05-30 14:27:21 +02:00
|
|
|
type: actor.type,
|
2018-05-18 09:56:21 +02:00
|
|
|
# public_key: actor.public_key,
|
|
|
|
suspended: actor.suspended,
|
|
|
|
url: actor.url,
|
2018-05-30 18:59:13 +02:00
|
|
|
avatar: actor.avatar_url,
|
|
|
|
banner: actor.banner_url,
|
2018-05-19 10:19:21 +02:00
|
|
|
organized_events: render_many(actor.organized_events, EventView, "event_for_actor.json")
|
2018-01-09 17:52:26 +01:00
|
|
|
}
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-06-06 17:42:53 +02:00
|
|
|
import Logger
|
2018-07-27 10:45:35 +02:00
|
|
|
Logger.debug(inspect(actor.type))
|
|
|
|
|
2018-06-06 17:42:53 +02:00
|
|
|
if actor.type == :Group do
|
|
|
|
Logger.debug("I'm a group !")
|
2018-07-27 10:45:35 +02:00
|
|
|
|
|
|
|
Map.put(
|
|
|
|
output,
|
|
|
|
:members,
|
|
|
|
render_many(Actors.members_for_group(actor), MemberView, "member.json")
|
|
|
|
)
|
2018-06-06 17:42:53 +02:00
|
|
|
else
|
|
|
|
Logger.debug("not a group")
|
|
|
|
output
|
|
|
|
end
|
2018-01-09 17:52:26 +01:00
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|