Merge branch 'expose-needed-ap-data-for-search' into 'main'

Expose isOnline through AP

Closes #1044

See merge request framasoft/mobilizon!1172
This commit is contained in:
Thomas Citharel 2022-02-08 15:34:48 +00:00
commit a0c5ddbc2e
3 changed files with 54 additions and 2 deletions

View File

@ -69,6 +69,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
"category" => "sc:category", "category" => "sc:category",
"uuid" => "sc:identifier", "uuid" => "sc:identifier",
"maximumAttendeeCapacity" => "sc:maximumAttendeeCapacity", "maximumAttendeeCapacity" => "sc:maximumAttendeeCapacity",
"remainingAttendeeCapacity" => "sc:remainingAttendeeCapacity",
"location" => %{ "location" => %{
"@id" => "sc:location", "@id" => "sc:location",
"@type" => "sc:Place" "@type" => "sc:Place"
@ -112,6 +113,14 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
"@id" => "mz:participationMessage", "@id" => "mz:participationMessage",
"@type" => "sc:Text" "@type" => "sc:Text"
}, },
"participantCount" => %{
"@id" => "mz:participantCount",
"@type" => "sc:Integer"
},
"isOnline" => %{
"@type" => "sc:Boolean",
"@id" => "mz:isOnline"
},
"PropertyValue" => "sc:PropertyValue", "PropertyValue" => "sc:PropertyValue",
"value" => "sc:value", "value" => "sc:value",
"propertyID" => "sc:propertyID", "propertyID" => "sc:propertyID",

View File

@ -110,6 +110,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
do: {[@ap_public], [event.organizer_actor.followers_url]}, do: {[@ap_public], [event.organizer_actor.followers_url]},
else: {[attributed_to_or_default(event).followers_url], [@ap_public]} else: {[attributed_to_or_default(event).followers_url], [@ap_public]}
participant_count = Mobilizon.Events.count_participant_participants(event.id)
%{ %{
"type" => "Event", "type" => "Event",
"to" => to, "to" => to,
@ -129,6 +131,9 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
"endTime" => event.ends_on |> shift_tz(event.options.timezone) |> date_to_string(), "endTime" => event.ends_on |> shift_tz(event.options.timezone) |> date_to_string(),
"tag" => event.tags |> build_tags(), "tag" => event.tags |> build_tags(),
"maximumAttendeeCapacity" => event.options.maximum_attendee_capacity, "maximumAttendeeCapacity" => event.options.maximum_attendee_capacity,
"remainingAttendeeCapacity" =>
remaining_attendee_capacity(event.options, participant_count),
"participantCount" => participant_count,
"repliesModerationOption" => event.options.comment_moderation, "repliesModerationOption" => event.options.comment_moderation,
"commentsEnabled" => event.options.comment_moderation == :allow_all, "commentsEnabled" => event.options.comment_moderation == :allow_all,
"anonymousParticipationEnabled" => event.options.anonymous_participation, "anonymousParticipationEnabled" => event.options.anonymous_participation,
@ -139,7 +144,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
"url" => event.url, "url" => event.url,
"inLanguage" => event.language, "inLanguage" => event.language,
"timezone" => event.options.timezone, "timezone" => event.options.timezone,
"contacts" => Enum.map(event.contacts, & &1.url) "contacts" => Enum.map(event.contacts, & &1.url),
"isOnline" => event.options.is_online
} }
|> maybe_add_physical_address(event) |> maybe_add_physical_address(event)
|> maybe_add_event_picture(event) |> maybe_add_event_picture(event)
@ -168,7 +174,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
"repliesModerationOption", "repliesModerationOption",
if(Map.get(object, "commentsEnabled", true), do: :allow_all, else: :closed) if(Map.get(object, "commentsEnabled", true), do: :allow_all, else: :closed)
), ),
timezone: calculate_timezone(object, address) timezone: calculate_timezone(object, address),
is_online: object["isOnline"] == true
} }
end end
@ -308,4 +315,19 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|> get_url() |> get_url()
|> fetch_actor() |> fetch_actor()
end end
@spec remaining_attendee_capacity(map(), integer()) :: integer() | nil
defp remaining_attendee_capacity(
%{maximum_attendee_capacity: maximum_attendee_capacity},
participant_count
)
when is_integer(maximum_attendee_capacity) and maximum_attendee_capacity > 0 do
maximum_attendee_capacity - participant_count
end
defp remaining_attendee_capacity(
%{maximum_attendee_capacity: _},
_participant_count
),
do: nil
end end

View File

@ -53,6 +53,8 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
organizer organizer
end end
participant_count = Mobilizon.Events.count_participant_participants(event.id)
json_ld = %{ json_ld = %{
"@context" => "https://schema.org", "@context" => "https://schema.org",
"@type" => "Event", "@type" => "Event",
@ -63,6 +65,9 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
"organizer" => organizer, "organizer" => organizer,
"location" => render_all_locations(event), "location" => render_all_locations(event),
"eventAttendanceMode" => event |> attendance_mode() |> event_attendance_mode(), "eventAttendanceMode" => event |> attendance_mode() |> event_attendance_mode(),
"maximumAttendeeCapacity" => event.options.maximum_attendee_capacity,
"remainingAttendeeCapacity" =>
remaining_attendee_capacity(event.options, participant_count),
"eventStatus" => "eventStatus" =>
if(event.status == :cancelled, if(event.status == :cancelled,
do: "https://schema.org/EventCancelled", do: "https://schema.org/EventCancelled",
@ -229,4 +234,20 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
@spec virtual_location_links(list()) :: list() @spec virtual_location_links(list()) :: list()
defp virtual_location_links(metadata), defp virtual_location_links(metadata),
do: Enum.filter(metadata, &String.contains?(&1.key, @livestream_keys)) do: Enum.filter(metadata, &String.contains?(&1.key, @livestream_keys))
# TODO: Make this in common with Mobilizon.Federation.ActivityStream.Converter.Event
@spec remaining_attendee_capacity(map(), integer()) :: integer() | nil
defp remaining_attendee_capacity(
%{maximum_attendee_capacity: maximum_attendee_capacity},
participant_count
)
when is_integer(maximum_attendee_capacity) and maximum_attendee_capacity > 0 do
maximum_attendee_capacity - participant_count
end
defp remaining_attendee_capacity(
%{maximum_attendee_capacity: _},
_participant_count
),
do: nil
end end