diff --git a/lib/federation/activity_stream/converter/event.ex b/lib/federation/activity_stream/converter/event.ex index 6328b56f..e40aab15 100644 --- a/lib/federation/activity_stream/converter/event.ex +++ b/lib/federation/activity_stream/converter/event.ex @@ -74,7 +74,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do medias: medias, begins_on: object["startTime"], ends_on: object["endTime"], - category: get_category(object["category"]), + category: Categories.get_category(object["category"]), visibility: visibility, join_options: Map.get(object, "joinMode", "free"), local: is_local?(object["id"]), @@ -331,15 +331,4 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do _participant_count ), 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 diff --git a/lib/mobilizon/events/categories.ex b/lib/mobilizon/events/categories.ex index 0a210f56..0ebb5a16 100644 --- a/lib/mobilizon/events/categories.ex +++ b/lib/mobilizon/events/categories.ex @@ -4,11 +4,27 @@ defmodule Mobilizon.Events.Categories do """ import Mobilizon.Web.Gettext + @default "MEETING" + + @spec default :: String.t() + def default do + @default + end + @spec list :: [%{id: atom(), label: String.t()}] def list do build_in_categories() ++ extra_categories() end + @spec get_category(String.t() | nil) :: String.t() + def get_category(category) do + if category in Enum.map(list(), &String.upcase(to_string(&1.id))) do + category + else + default() + end + end + defp build_in_categories do [ %{ diff --git a/lib/service/global_search/search_mobilizon.ex b/lib/service/global_search/search_mobilizon.ex index 47bef941..41d191ee 100644 --- a/lib/service/global_search/search_mobilizon.ex +++ b/lib/service/global_search/search_mobilizon.ex @@ -5,7 +5,7 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do alias Mobilizon.Actors.Actor alias Mobilizon.Addresses.Address - alias Mobilizon.Events.Tag + alias Mobilizon.Events.{Categories, Tag} alias Mobilizon.Service.GlobalSearch.{EventResult, GroupResult, Provider} alias Mobilizon.Service.HTTP.GenericJSONClient alias Mobilizon.Storage.Page @@ -187,7 +187,7 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do ends_on: parse_date(data["endTime"]), url: data["url"], picture: picture, - category: String.to_existing_atom(String.downcase(data["category"])), + category: String.to_existing_atom(Categories.get_category(data["category"])), organizer_actor: %Actor{ id: data["creator"]["id"], name: data["creator"]["displayName"],