Add a VirtualLocation field to the event URL itself when location is not

defined

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-08-10 16:22:15 +02:00
parent 040aa56763
commit 992e3af237
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -22,7 +22,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
# We assume for now performer == organizer
"performer" => organizer,
"organizer" => organizer,
"location" => render_one(event.physical_address, ObjectView, "place.json", as: :address),
"location" => render_location(event),
"eventStatus" =>
if(event.status == :cancelled,
do: "https://schema.org/EventCancelled",
@ -67,8 +67,6 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
}
end
def render("place.json", nil), do: %{}
def render("post.json", %{post: %Post{} = post}) do
%{
"@context" => "https://schema.org",
@ -82,4 +80,16 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
"dateModified" => post.updated_at
}
end
defp render_location(%Event{physical_address: %Address{} = address}),
do: render_one(address, ObjectView, "place.json", as: :address)
# For now the Virtual Location of an event is it's own URL,
# but in the future it will be a special field
defp render_location(%Event{url: event_url}) do
%{
"@type" => "VirtualLocation",
"url" => event_url
}
end
end