1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-23 00:14:48 +00:00

Add "eventAttendanceMode" to JSON-ld schema.org event representation

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-11-15 11:08:18 +01:00
parent fea97f3713
commit bcf17fe30b
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -3,7 +3,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.{Event, Participant, ParticipantRole}
alias Mobilizon.Events.{Event, EventOptions, Participant, ParticipantRole}
alias Mobilizon.Posts.Post
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.JsonLD.ObjectView
@ -59,6 +59,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
"performer" => organizer,
"organizer" => organizer,
"location" => render_location(event),
"eventAttendanceMode" => eventAttendanceMode(event),
"eventStatus" =>
if(event.status == :cancelled,
do: "https://schema.org/EventCancelled",
@ -182,4 +183,20 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
do: render_one(address, ObjectView, "address.json", as: :address)
defp render_address(_), do: nil
@livestream_keys ["mz:live", "mz:visio"]
defp eventAttendanceMode(%Event{options: %EventOptions{is_online: true}}),
do: "https://schema.org/OnlineEventAttendanceMode"
defp eventAttendanceMode(%Event{physical_address: %Address{}, metadata: metadata}) do
if Enum.any?(metadata, &String.contains?(&1["key"], @livestream_keys)) do
"https://schema.org/MixedEventAttendanceMode"
else
"https://schema.org/OfflineEventAttendanceMode"
end
end
defp eventAttendanceMode(%Event{}),
do: "https://schema.org/OfflineEventAttendanceMode"
end