Properly fallback to MEETING category if category is not in the

allowlist

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-06 14:42:01 +02:00
parent 2978ae5d1e
commit 501e0d12e4
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -8,6 +8,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Categories
alias Mobilizon.Events.Event, as: EventModel alias Mobilizon.Events.Event, as: EventModel
alias Mobilizon.Medias.Media alias Mobilizon.Medias.Media
@ -73,7 +74,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
medias: medias, medias: medias,
begins_on: object["startTime"], begins_on: object["startTime"],
ends_on: object["endTime"], ends_on: object["endTime"],
category: object["category"], category: get_category(object["category"]),
visibility: visibility, visibility: visibility,
join_options: Map.get(object, "joinMode", "free"), join_options: Map.get(object, "joinMode", "free"),
local: is_local?(object["id"]), local: is_local?(object["id"]),
@ -330,4 +331,15 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
_participant_count _participant_count
), ),
do: nil do: nil
@spec get_category(String.t() | nil) :: String.t()
defp get_category(nil), do: "MEETING"
defp get_category(category) when is_binary(category) do
if category in Enum.map(Categories.list(), &String.upcase(to_string(&1.id))) do
category
else
get_category(nil)
end
end
end end