From 5e8f9afb62f642af90b3ce7bb3bc561224a18b4b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 4 Dec 2023 13:48:04 +0100 Subject: [PATCH] fix(activitypub): compact ical:status in activitystream data Was kept for no other reason than disambiguation with https://schema.org/status, but no need if we specify the correct alias in the context. Keeps a fallback for older versions compatibility Closes #1378 Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/utils.ex | 4 ++++ lib/federation/activity_stream/converter/event.ex | 8 +++++++- test/federation/activity_pub/types/events_test.exs | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/federation/activity_pub/utils.ex b/lib/federation/activity_pub/utils.ex index eeb802a88..51441fc05 100644 --- a/lib/federation/activity_pub/utils.ex +++ b/lib/federation/activity_pub/utils.ex @@ -165,6 +165,10 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do "todos" => %{ "@id" => "mz:todos", "@type" => "@id" + }, + "status" => %{ + "@id" => "ical:status", + "@type" => "ical:status" } } ] diff --git a/lib/federation/activity_stream/converter/event.ex b/lib/federation/activity_stream/converter/event.ex index d08c61db0..2eca4e805 100644 --- a/lib/federation/activity_stream/converter/event.ex +++ b/lib/federation/activity_stream/converter/event.ex @@ -81,7 +81,11 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do external_participation_url: object["externalParticipationUrl"], options: options, metadata: metadata, - status: object |> Map.get("ical:status", "CONFIRMED") |> String.downcase(), + # Remove fallback in MBZ 5.x + status: + object + |> Map.get("status", Map.get(object, "ical:status", "CONFIRMED")) + |> String.downcase(), online_address: object |> Map.get("attachment", []) |> get_online_address(), phone_address: object["phoneAddress"], draft: object["draft"] == true, @@ -142,7 +146,9 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do "anonymousParticipationEnabled" => event.options.anonymous_participation, "attachment" => Enum.map(event.metadata, &EventMetadataConverter.metadata_to_as/1), "draft" => event.draft, + # Remove me in MBZ 5.x "ical:status" => event.status |> to_string |> String.upcase(), + "status" => event.status |> to_string |> String.upcase(), "id" => event.url, "url" => event.url, "inLanguage" => event.language, diff --git a/test/federation/activity_pub/types/events_test.exs b/test/federation/activity_pub/types/events_test.exs index 99589f043..3e875e27a 100644 --- a/test/federation/activity_pub/types/events_test.exs +++ b/test/federation/activity_pub/types/events_test.exs @@ -49,6 +49,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do "name" => @event_title, "repliesModerationOption" => nil, "startTime" => @event_begins_on, + "status" => "CONFIRMED", "tag" => [], "to" => [@ap_public], "type" => "Event" @@ -96,6 +97,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do "name" => @event_title, "repliesModerationOption" => nil, "startTime" => @event_begins_on, + "status" => "CONFIRMED", "tag" => [], "to" => [^followers_url], "type" => "Event" @@ -152,6 +154,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do "name" => @event_title, "repliesModerationOption" => nil, "startTime" => @event_begins_on, + "status" => "CONFIRMED", "tag" => [], "to" => [@ap_public], "type" => "Event" @@ -200,6 +203,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do "name" => @event_updated_title, "repliesModerationOption" => nil, "startTime" => @event_begins_on, + "status" => "CONFIRMED", "tag" => [], "to" => [@ap_public], "type" => "Event" @@ -260,6 +264,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do "name" => @event_updated_title, "repliesModerationOption" => nil, "startTime" => @event_begins_on, + "status" => "CONFIRMED", "tag" => [], "to" => [@ap_public], "type" => "Event" @@ -320,6 +325,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do "name" => @event_updated_title, "repliesModerationOption" => nil, "startTime" => @event_begins_on, + "status" => "CONFIRMED", "tag" => [], "to" => [@ap_public], "type" => "Event"