From 4a16f572d8889e92067d93840438dda38cef8e5d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 14:01:57 +0200 Subject: [PATCH 1/6] Fix build after !1261 Signed-off-by: Thomas Citharel --- js/src/services/EventMetadata.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/src/services/EventMetadata.ts b/js/src/services/EventMetadata.ts index 94607466a..4d8d5981b 100644 --- a/js/src/services/EventMetadata.ts +++ b/js/src/services/EventMetadata.ts @@ -59,16 +59,16 @@ export const eventMetaDataList: IEventMetadataDescription[] = [ { icon: "smoking-off", key: "mz:accessibility:smokeFree", - label: i18n.t("Smoke free") as string, - description: i18n.t( + label: t("Smoke free") as string, + description: t( "Whether smoking is prohibited during the event" ) as string, value: "false", type: EventMetadataType.BOOLEAN, keyType: EventMetadataKeyType.PLAIN, choices: { - true: i18n.t("Smoke free") as string, - false: i18n.t("Smoking allowed") as string, + true: t("Smoke free") as string, + false: t("Smoking allowed") as string, }, category: EventMetadataCategories.ACCESSIBILITY, }, From ca9826e2990102ae38615881e3d7798aa34ae3df Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 14:02:25 +0200 Subject: [PATCH 2/6] Improve related events Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/event.ex | 5 +--- lib/mobilizon/events/events.ex | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/lib/graphql/resolvers/event.ex b/lib/graphql/resolvers/event.ex index 1b7632c8d..40d8dd906 100644 --- a/lib/graphql/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -211,10 +211,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do # We get the organizer's next public event events = event - |> organizer_next_public_event() - # We find similar events with the same tags - |> similar_events_common_tags(event) - # TODO: We should use tag_relations to find more appropriate events + |> Events.related_events() # We've considered all recommended events, so we fetch the latest events |> add_latest_events() # We remove the same event from the results diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 3890b1031..22a3ec484 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -1686,6 +1686,58 @@ defmodule Mobilizon.Events do |> Repo.all() end + @threshold_related_value 7 + + def related_events(%Event{ + id: event_id, + tags: tags, + physical_address: %Address{geom: geom}, + category: category, + language: language + }) do + event_tags_ids = Enum.map(tags, & &1.id) + + Event + |> join(:left, [e], et in "events_tags", on: e.id == et.event_id) + |> join(:left, [e], a in Address, on: e.physical_address_id == a.id) + |> where( + [e, et, a], + fragment( + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", + e.language, + ^language, + et.tag_id, + ^event_tags_ids, + e.category, + ^category, + a.geom, + ^geom, + a.geom, + 5000, + @threshold_related_value + ) + ) + # |> where([e], e.begins_on > ^DateTime.utc_now()) + |> where([e], e.id != ^event_id) + |> order_by( + [e, et, a], + fragment( + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", + e.language, + ^language, + et.tag_id, + ^event_tags_ids, + e.category, + ^category, + a.geom, + ^geom, + a.geom, + 5000 + ) + ) + |> Repo.all() + end + @spec list_participations_for_user_query(integer()) :: Ecto.Query.t() defp list_participations_for_user_query(user_id) do from( From 4f1465e84d9f7aa393d0a29e8cb57c39c48c1785 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 14:37:14 +0200 Subject: [PATCH 3/6] Add distinct on suggested events Signed-off-by: Thomas Citharel --- lib/mobilizon/events/events.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 22a3ec484..9bef1512c 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -1698,6 +1698,7 @@ defmodule Mobilizon.Events do event_tags_ids = Enum.map(tags, & &1.id) Event + |> distinct([e], e.id) |> join(:left, [e], et in "events_tags", on: e.id == et.event_id) |> join(:left, [e], a in Address, on: e.physical_address_id == a.id) |> where( From f0c8fa2525023edf461b4ac5732b0f0197e53de5 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 19:26:35 +0200 Subject: [PATCH 4/6] Handle events with no physical location Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/event.ex | 20 -------------------- lib/mobilizon/events/events.ex | 11 ++++++----- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/lib/graphql/resolvers/event.ex b/lib/graphql/resolvers/event.ex index 40d8dd906..31c2c3d4e 100644 --- a/lib/graphql/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -222,26 +222,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do {:ok, events} end - @spec organizer_next_public_event(Event.t()) :: list(Event.t()) - defp organizer_next_public_event(%Event{attributed_to: %Actor{} = group, uuid: uuid}) do - [Events.get_upcoming_public_event_for_actor(group, uuid)] - |> Enum.filter(&is_map/1) - end - - defp organizer_next_public_event(%Event{organizer_actor: %Actor{} = profile, uuid: uuid}) do - [Events.get_upcoming_public_event_for_actor(profile, uuid)] - |> Enum.filter(&is_map/1) - end - - @spec similar_events_common_tags(list(Event.t()), Event.t()) :: list(Event.t()) - defp similar_events_common_tags(events, %Event{tags: tags, uuid: uuid}) do - events - |> Enum.concat(Events.list_events_by_tags(tags, @number_of_related_events)) - |> Enum.filter(fn event -> event.uuid != uuid end) - # uniq_by : It's possible event_from_same_actor is inside events_from_tags - |> uniq_events() - end - @spec add_latest_events(list(Event.t())) :: list(Event.t()) defp add_latest_events(events) do if @number_of_related_events - length(events) > 0 do diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 9bef1512c..07bf63af9 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -1691,11 +1691,12 @@ defmodule Mobilizon.Events do def related_events(%Event{ id: event_id, tags: tags, - physical_address: %Address{geom: geom}, + physical_address: physical_address, category: category, language: language }) do event_tags_ids = Enum.map(tags, & &1.id) + geom = if is_nil(physical_address), do: nil, else: physical_address.geom Event |> distinct([e], e.id) @@ -1704,14 +1705,14 @@ defmodule Mobilizon.Events do |> where( [e, et, a], fragment( - "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", e.language, ^language, et.tag_id, ^event_tags_ids, e.category, ^category, - a.geom, + ^geom, ^geom, a.geom, 5000, @@ -1723,14 +1724,14 @@ defmodule Mobilizon.Events do |> order_by( [e, et, a], fragment( - "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", e.language, ^language, et.tag_id, ^event_tags_ids, e.category, ^category, - a.geom, + ^geom, ^geom, a.geom, 5000 From 160115306298b0a108101f012018420a44367bb2 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 19:33:54 +0200 Subject: [PATCH 5/6] Add all proper filters for related events Signed-off-by: Thomas Citharel --- lib/mobilizon/events/events.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 07bf63af9..9ad6d0550 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -1688,6 +1688,7 @@ defmodule Mobilizon.Events do @threshold_related_value 7 + @spec related_events(Event.t()) :: list(Event.t()) def related_events(%Event{ id: event_id, tags: tags, @@ -1702,6 +1703,10 @@ defmodule Mobilizon.Events do |> distinct([e], e.id) |> join(:left, [e], et in "events_tags", on: e.id == et.event_id) |> join(:left, [e], a in Address, on: e.physical_address_id == a.id) + |> events_for_begins_on(%{}) + |> filter_draft() + |> filter_local_or_from_followed_instances_events() + |> filter_public_visibility() |> where( [e, et, a], fragment( @@ -1719,7 +1724,6 @@ defmodule Mobilizon.Events do @threshold_related_value ) ) - # |> where([e], e.begins_on > ^DateTime.utc_now()) |> where([e], e.id != ^event_id) |> order_by( [e, et, a], From 5055bd4adcf84cc0fc30f483437a0a1924e64d68 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 19:45:29 +0200 Subject: [PATCH 6/6] Consider the events from the same organizer actor or group in first Signed-off-by: Thomas Citharel --- lib/mobilizon/events/events.ex | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 9ad6d0550..cfc3804e0 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -1693,11 +1693,14 @@ defmodule Mobilizon.Events do id: event_id, tags: tags, physical_address: physical_address, + organizer_actor: %Actor{id: organizer_actor_id}, + attributed_to: attributed_to, category: category, language: language }) do event_tags_ids = Enum.map(tags, & &1.id) geom = if is_nil(physical_address), do: nil, else: physical_address.geom + group_id = if is_nil(attributed_to), do: nil, else: attributed_to.id Event |> distinct([e], e.id) @@ -1710,13 +1713,18 @@ defmodule Mobilizon.Events do |> where( [e, et, a], fragment( - "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? = ?)::int * 2 + (?::int is null or ? = ?)::int * 2 + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", e.language, ^language, et.tag_id, ^event_tags_ids, e.category, ^category, + e.organizer_actor_id, + ^organizer_actor_id, + ^group_id, + e.attributed_to_id, + ^group_id, ^geom, ^geom, a.geom, @@ -1728,13 +1736,18 @@ defmodule Mobilizon.Events do |> order_by( [e, et, a], fragment( - "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? = ?)::int * 2 + (?::int is null or ? = ?)::int * 2 + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", e.language, ^language, et.tag_id, ^event_tags_ids, e.category, ^category, + e.organizer_actor_id, + ^organizer_actor_id, + ^group_id, + e.attributed_to_id, + ^group_id, ^geom, ^geom, a.geom,