This commit is contained in:
Thomas Citharel
2018-11-12 09:05:31 +01:00
parent 6e691640de
commit 5721c5fe05
16 changed files with 289 additions and 228 deletions

View File

@@ -32,6 +32,8 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
"owner" => actor.url,
"publicKeyPem" => public_key
},
# TODO : Make have actors have an uuid
# "uuid" => actor.uuid
"endpoints" => %{
"sharedInbox" => actor.shared_inbox_url
}
@@ -135,6 +137,7 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
"Announce"
end,
"actor" => activity.actor,
# Not sure if needed since this is used into outbox
"published" => Timex.now(),
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"object" =>
@@ -143,9 +146,10 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
render_one(activity.data, ObjectView, "event.json", as: :event)
:Comment ->
render_one(activity.data, ObjectView, "note.json", as: :note)
render_one(activity.data, ObjectView, "comment.json", as: :comment)
end
}
|> Map.merge(Utils.make_json_ld_header())
end
def collection(collection, iri, page, total \\ nil) do

View File

@@ -2,20 +2,7 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do
use MobilizonWeb, :view
alias MobilizonWeb.ActivityPub.ObjectView
alias Mobilizon.Service.ActivityPub.Transmogrifier
@base %{
"@context" => [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
%{
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
"sensitive" => "as:sensitive",
"Hashtag" => "as:Hashtag",
"toot" => "http://joinmastodon.org/ns#",
"Emoji" => "toot:Emoji"
}
]
}
alias Mobilizon.Service.ActivityPub.Utils
def render("event.json", %{event: event}) do
event = %{
@@ -24,29 +11,36 @@ defmodule MobilizonWeb.ActivityPub.ObjectView do
"name" => event.title,
"category" => render_one(event.category, ObjectView, "category.json", as: :category),
"content" => event.description,
"mediaType" => "text/markdown",
"mediaType" => "text/html",
"published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
"updated" => Timex.format!(event.updated_at, "{ISO:Extended}")
}
Map.merge(event, @base)
Map.merge(event, Utils.make_json_ld_header())
end
def render("note.json", %{note: note}) do
event = %{
def render("comment.json", %{comment: comment}) do
comment = %{
"actor" => comment.actor.url,
"uuid" => comment.uuid,
# The activity should have attributedTo, not the comment itself
# "attributedTo" => comment.attributed_to,
"type" => "Note",
"id" => note.url,
"content" => note.text,
"mediaType" => "text/markdown",
"published" => Timex.format!(note.inserted_at, "{ISO:Extended}"),
"updated" => Timex.format!(note.updated_at, "{ISO:Extended}")
"id" => comment.url,
"content" => comment.text,
"mediaType" => "text/html",
"published" => Timex.format!(comment.inserted_at, "{ISO:Extended}"),
"updated" => Timex.format!(comment.updated_at, "{ISO:Extended}")
}
Map.merge(event, @base)
Map.merge(comment, Utils.make_json_ld_header())
end
def render("category.json", %{category: category}) do
%{"title" => category.title}
%{
"identifier" => category.id,
"name" => category.title
}
end
def render("category.json", %{category: nil}) do