Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-05-30 14:27:21 +02:00
parent 2f0a29aa86
commit cac4dd3ca3
25 changed files with 669 additions and 46 deletions

View File

@@ -9,6 +9,7 @@ defmodule EventosWeb.ActivityPub.ActorView do
alias Eventos.Service.ActivityPub
alias Eventos.Service.ActivityPub.Transmogrifier
alias Eventos.Service.ActivityPub.Utils
alias Eventos.Activity
import Ecto.Query
def render("actor.json", %{actor: actor}) do
@@ -123,10 +124,10 @@ defmodule EventosWeb.ActivityPub.ActorView do
end
end
def render("activity.json", %{activity: activity}) do
def render("activity.json", %{activity: %Activity{local: local} = activity}) do
%{
"id" => activity.data.url <> "/activity",
"type" => "Create",
"type" => if local do "Create" else "Announce" end,
"actor" => activity.data.organizer_actor.url,
"published" => Timex.now(),
"to" => ["https://www.w3.org/ns/activitystreams#Public"],

View File

@@ -1,5 +1,6 @@
defmodule EventosWeb.ActivityPub.ObjectView do
use EventosWeb, :view
alias EventosWeb.ActivityPub.ObjectView
alias Eventos.Service.ActivityPub.Transmogrifier
@base %{
"@context" => [
@@ -22,7 +23,7 @@ defmodule EventosWeb.ActivityPub.ObjectView do
"type" => "Event",
"id" => event.url,
"name" => event.title,
"category" => %{"title" => event.category.title},
"category" => render_one(event.category, ObjectView, "category.json", as: :category),
"content" => event.description,
"mediaType" => "text/markdown",
"published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
@@ -32,6 +33,10 @@ defmodule EventosWeb.ActivityPub.ObjectView do
end
def render("category.json", %{category: category}) do
category
%{"title" => category.title}
end
def render("category.json", %{category: nil}) do
nil
end
end

View File

@@ -23,6 +23,7 @@ defmodule EventosWeb.ActorView do
domain: actor.domain,
display_name: actor.name,
description: actor.summary,
type: actor.type,
# public_key: actor.public_key,
suspended: actor.suspended,
url: actor.url,
@@ -35,6 +36,7 @@ defmodule EventosWeb.ActorView do
domain: actor.domain,
display_name: actor.name,
description: actor.summary,
type: actor.type,
# public_key: actor.public_key,
suspended: actor.suspended,
url: actor.url,

View File

@@ -0,0 +1,18 @@
defmodule EventosWeb.BotView do
use EventosWeb, :view
alias EventosWeb.BotView
def render("index.json", %{bots: bots}) do
%{data: render_many(bots, BotView, "bot.json")}
end
def render("show.json", %{bot: bot}) do
%{data: render_one(bot, BotView, "bot.json")}
end
def render("bot.json", %{bot: bot}) do
%{id: bot.id,
source: bot.source,
type: bot.type}
end
end

View File

@@ -34,6 +34,7 @@ defmodule EventosWeb.EventView do
organizer: %{
username: event.organizer_actor.preferred_username
},
type: "Event",
}
end
@@ -46,6 +47,7 @@ defmodule EventosWeb.EventView do
organizer: render_one(event.organizer_actor, ActorView, "acccount_basic.json"),
participants: render_many(event.participants, ActorView, "show_basic.json"),
address: render_one(event.address, AddressView, "address.json"),
type: "Event",
}
end
end

View File

@@ -0,0 +1,16 @@
defmodule EventosWeb.SearchView do
@moduledoc """
View for Events
"""
use EventosWeb, :view
alias EventosWeb.{EventView, ActorView, GroupView, AddressView}
def render("search.json", %{events: events, actors: actors}) do
%{
data: %{
events: render_many(events, EventView, "event_simple.json"),
actors: render_many(actors, ActorView, "acccount_basic.json"),
}
}
end
end