Merge branch 'handle-categories-from-global-search' into 'main'
Handle unknown categories from global search See merge request framasoft/mobilizon!1280
This commit is contained in:
commit
200e4d2c56
@ -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
|
||||
|
@ -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
|
||||
[
|
||||
%{
|
||||
|
@ -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"],
|
||||
|
Loading…
Reference in New Issue
Block a user