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