Handle unknown categories from global search
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
0265e0220e
commit
0758995ac7
@ -74,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: get_category(object["category"]),
|
category: Categories.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"]),
|
||||||
@ -331,15 +331,4 @@ 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
|
||||||
|
@ -4,11 +4,27 @@ defmodule Mobilizon.Events.Categories do
|
|||||||
"""
|
"""
|
||||||
import Mobilizon.Web.Gettext
|
import Mobilizon.Web.Gettext
|
||||||
|
|
||||||
|
@default "MEETING"
|
||||||
|
|
||||||
|
@spec default :: String.t()
|
||||||
|
def default do
|
||||||
|
@default
|
||||||
|
end
|
||||||
|
|
||||||
@spec list :: [%{id: atom(), label: String.t()}]
|
@spec list :: [%{id: atom(), label: String.t()}]
|
||||||
def list do
|
def list do
|
||||||
build_in_categories() ++ extra_categories()
|
build_in_categories() ++ extra_categories()
|
||||||
end
|
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
|
defp build_in_categories do
|
||||||
[
|
[
|
||||||
%{
|
%{
|
||||||
|
@ -5,7 +5,7 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
|||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Events.Tag
|
alias Mobilizon.Events.{Categories, Tag}
|
||||||
alias Mobilizon.Service.GlobalSearch.{EventResult, GroupResult, Provider}
|
alias Mobilizon.Service.GlobalSearch.{EventResult, GroupResult, Provider}
|
||||||
alias Mobilizon.Service.HTTP.GenericJSONClient
|
alias Mobilizon.Service.HTTP.GenericJSONClient
|
||||||
alias Mobilizon.Storage.Page
|
alias Mobilizon.Storage.Page
|
||||||
@ -187,7 +187,7 @@ defmodule Mobilizon.Service.GlobalSearch.SearchMobilizon do
|
|||||||
ends_on: parse_date(data["endTime"]),
|
ends_on: parse_date(data["endTime"]),
|
||||||
url: data["url"],
|
url: data["url"],
|
||||||
picture: picture,
|
picture: picture,
|
||||||
category: String.to_existing_atom(String.downcase(data["category"])),
|
category: String.to_existing_atom(Categories.get_category(data["category"])),
|
||||||
organizer_actor: %Actor{
|
organizer_actor: %Actor{
|
||||||
id: data["creator"]["id"],
|
id: data["creator"]["id"],
|
||||||
name: data["creator"]["displayName"],
|
name: data["creator"]["displayName"],
|
||||||
|
Loading…
Reference in New Issue
Block a user