2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.ActivityPub.ObjectView do
|
|
|
|
use MobilizonWeb, :view
|
|
|
|
alias MobilizonWeb.ActivityPub.ObjectView
|
2018-11-12 09:05:31 +01:00
|
|
|
alias Mobilizon.Service.ActivityPub.Utils
|
2018-05-17 11:32:23 +02:00
|
|
|
|
|
|
|
def render("event.json", %{event: event}) do
|
|
|
|
event = %{
|
|
|
|
"type" => "Event",
|
2018-11-12 18:17:53 +01:00
|
|
|
"actor" => event["actor"],
|
|
|
|
"id" => event["id"],
|
|
|
|
"name" => event["title"],
|
|
|
|
"category" => render_one(event["category"], ObjectView, "category.json", as: :category),
|
|
|
|
"content" => event["summary"],
|
|
|
|
"mediaType" => "text/html"
|
|
|
|
# "published" => Timex.format!(event.inserted_at, "{ISO:Extended}"),
|
|
|
|
# "updated" => Timex.format!(event.updated_at, "{ISO:Extended}")
|
2018-05-17 11:32:23 +02:00
|
|
|
}
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-11-12 09:05:31 +01:00
|
|
|
Map.merge(event, Utils.make_json_ld_header())
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 09:05:31 +01:00
|
|
|
def render("comment.json", %{comment: comment}) do
|
|
|
|
comment = %{
|
2018-11-12 18:17:53 +01:00
|
|
|
"actor" => comment["actor"],
|
|
|
|
"uuid" => comment["uuid"],
|
2018-11-12 09:05:31 +01:00
|
|
|
# The activity should have attributedTo, not the comment itself
|
|
|
|
# "attributedTo" => comment.attributed_to,
|
2018-08-24 11:34:00 +02:00
|
|
|
"type" => "Note",
|
2018-11-12 18:17:53 +01:00
|
|
|
"id" => comment["id"],
|
|
|
|
"content" => comment["content"],
|
|
|
|
"mediaType" => "text/html"
|
|
|
|
# "published" => Timex.format!(comment.inserted_at, "{ISO:Extended}"),
|
|
|
|
# "updated" => Timex.format!(comment.updated_at, "{ISO:Extended}")
|
2018-08-24 11:34:00 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 09:05:31 +01:00
|
|
|
Map.merge(comment, Utils.make_json_ld_header())
|
2018-08-24 11:34:00 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 23:30:47 +01:00
|
|
|
def render("category.json", %{category: category}) when not is_nil(category) do
|
2018-11-12 09:05:31 +01:00
|
|
|
%{
|
|
|
|
"identifier" => category.id,
|
|
|
|
"name" => category.title
|
|
|
|
}
|
2018-05-30 14:27:21 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 23:30:47 +01:00
|
|
|
def render("category.json", %{category: _category}) do
|
2018-05-30 14:27:21 +02:00
|
|
|
nil
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
end
|