2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.ActivityPub.ObjectView do
|
|
|
|
use MobilizonWeb, :view
|
2018-11-12 09:05:31 +01:00
|
|
|
alias Mobilizon.Service.ActivityPub.Utils
|
2019-04-25 19:05:05 +02:00
|
|
|
alias Mobilizon.Activity
|
2018-05-17 11:32:23 +02:00
|
|
|
|
|
|
|
def render("event.json", %{event: event}) do
|
2019-03-01 18:30:46 +01:00
|
|
|
{:ok, html, []} = Earmark.as_html(event["summary"])
|
|
|
|
|
2018-05-17 11:32:23 +02:00
|
|
|
event = %{
|
|
|
|
"type" => "Event",
|
2019-03-01 18:30:46 +01:00
|
|
|
"attributedTo" => event["actor"],
|
2018-11-12 18:17:53 +01:00
|
|
|
"id" => event["id"],
|
|
|
|
"name" => event["title"],
|
2019-02-22 16:54:01 +01:00
|
|
|
"category" => event["category"],
|
2019-03-01 18:30:46 +01:00
|
|
|
"content" => html,
|
|
|
|
"source" => %{
|
|
|
|
"content" => event["summary"],
|
|
|
|
"mediaType" => "text/markdown"
|
|
|
|
},
|
|
|
|
"mediaType" => "text/html",
|
|
|
|
"published" => event["publish_at"],
|
|
|
|
"updated" => event["updated_at"]
|
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
|
2019-04-25 19:05:05 +02:00
|
|
|
|
|
|
|
def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do
|
|
|
|
%{
|
|
|
|
"id" => data["id"],
|
|
|
|
"type" =>
|
|
|
|
if local do
|
|
|
|
"Create"
|
|
|
|
else
|
|
|
|
"Announce"
|
|
|
|
end,
|
|
|
|
"actor" => activity.actor,
|
|
|
|
# Not sure if needed since this is used into outbox
|
|
|
|
"published" => Timex.now(),
|
|
|
|
"to" => activity.recipients,
|
|
|
|
"object" =>
|
|
|
|
case data["type"] do
|
|
|
|
"Event" ->
|
|
|
|
render_one(data, ObjectView, "event.json", as: :event)
|
|
|
|
|
|
|
|
"Note" ->
|
|
|
|
render_one(data, ObjectView, "comment.json", as: :comment)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|> Map.merge(Utils.make_json_ld_header())
|
|
|
|
end
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|