From 1f23bb421e080941d1e7cd43a05f60352a9d3247 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 7 Nov 2022 18:55:49 +0100 Subject: [PATCH 1/6] Increase timeout needed to build page Signed-off-by: Thomas Citharel --- lib/mobilizon/storage/page.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mobilizon/storage/page.ex b/lib/mobilizon/storage/page.ex index 43b9ebc5..29f14f65 100644 --- a/lib/mobilizon/storage/page.ex +++ b/lib/mobilizon/storage/page.ex @@ -31,7 +31,7 @@ defmodule Mobilizon.Storage.Page do fn -> Repo.all(paginate(query, page, limit)) end ] |> Enum.map(&Task.async/1) - |> Enum.map(&Task.await/1) + |> Enum.map(&Task.await(&1, 15_000)) %__MODULE__{total: total, elements: elements} end From 7b2eb82d6fb2d701afcc6ed3a96dddc9ddcf24a4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 7 Nov 2022 18:59:46 +0100 Subject: [PATCH 2/6] Handle nothing found by unsplash for location Closes #1187 Signed-off-by: Thomas Citharel --- lib/service/pictures/unsplash.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/service/pictures/unsplash.ex b/lib/service/pictures/unsplash.ex index 307ef292..4a403a19 100644 --- a/lib/service/pictures/unsplash.ex +++ b/lib/service/pictures/unsplash.ex @@ -24,7 +24,9 @@ defmodule Mobilizon.Service.Pictures.Unsplash do GenericJSONClient.client(headers: [{:Authorization, "Client-ID #{unsplash_access_key()}"}]) with {:ok, %{status: 200, body: body}} <- GenericJSONClient.get(client, url), - selected_picture <- Enum.random(body["results"]) do + results <- body["results"], + {:empty, false} <- {:empty, Enum.empty?(results)}, + selected_picture <- Enum.random(results) do %Information{ url: selected_picture["urls"]["small"], author: %{ @@ -37,6 +39,9 @@ defmodule Mobilizon.Service.Pictures.Unsplash do } } else + {:empty, false} -> + nil + _ -> nil end From bb86ca54138b79e517a6a7640c33dc063f913330 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 7 Nov 2022 19:05:20 +0100 Subject: [PATCH 3/6] Handle :http_not_found as an error when deleting an object Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/transmogrifier.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/federation/activity_pub/transmogrifier.ex b/lib/federation/activity_pub/transmogrifier.ex index 2e458056..dabb5a9a 100644 --- a/lib/federation/activity_pub/transmogrifier.ex +++ b/lib/federation/activity_pub/transmogrifier.ex @@ -637,6 +637,10 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do {:error, err} -> Logger.debug(inspect(err)) {:error, err} + + {:error, :http_not_found, err} -> + Logger.debug(inspect(err)) + {:error, err} end end end From af3110955d070f752816b05ab19bce0cd0e9c590 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 7 Nov 2022 19:07:36 +0100 Subject: [PATCH 4/6] Handle suspending actors with special type Closes #1183 Signed-off-by: Thomas Citharel --- lib/service/actor_suspension.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/service/actor_suspension.ex b/lib/service/actor_suspension.ex index 35b64069..ca9c2fc8 100644 --- a/lib/service/actor_suspension.ex +++ b/lib/service/actor_suspension.ex @@ -22,6 +22,7 @@ defmodule Mobilizon.Service.ActorSuspension do @actor_preloads [:user, :organized_events, :participations, :comments] @delete_actor_default_options [reserve_username: true, suspension: false] + @valid_actor_types [:Person, :Group] @doc """ Deletes an actor. @@ -119,7 +120,8 @@ defmodule Mobilizon.Service.ActorSuspension do end @spec notify_event_participants_from_suspension(Actor.t()) :: :ok - defp notify_event_participants_from_suspension(%Actor{id: actor_id} = actor) do + defp notify_event_participants_from_suspension(%Actor{id: actor_id, type: actor_type} = actor) + when actor_type in @valid_actor_types do actor |> get_actor_organizer_events_participations() |> preload([:actor, :event]) @@ -134,6 +136,8 @@ defmodule Mobilizon.Service.ActorSuspension do |> Enum.each(&Events.delete_participant/1) end + defp notify_event_participants_from_suspension(_), do: :ok + @spec get_actor_organizer_events_participations(Actor.t()) :: Ecto.Query.t() defp get_actor_organizer_events_participations(%Actor{type: :Person, id: actor_id}) do do_get_actor_organizer_events_participations() From 16b1e0080c69ccd0edeff926712560f3b9083738 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 7 Nov 2022 19:11:15 +0100 Subject: [PATCH 5/6] Add fallback handler for can_send_activity? Signed-off-by: Thomas Citharel --- lib/service/notifier/email.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/service/notifier/email.ex b/lib/service/notifier/email.ex index 64b48b24..1d5265d1 100644 --- a/lib/service/notifier/email.ex +++ b/lib/service/notifier/email.ex @@ -94,6 +94,15 @@ defmodule Mobilizon.Service.Notifier.Email do ) end + defp can_send_activity?(activity, user, options) do + Logger.warn("Can't check if user #{inspect(user)} can be sent an activity", + activity: inspect(activity), + options: inspect(options) + ) + + false + end + @spec match_group_notifications_setting( non_neg_integer(), String.t(), From 035ff134f5cd951a285a0907ddb1382e675ce65d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 7 Nov 2022 19:44:16 +0100 Subject: [PATCH 6/6] Properly log if we can't notify group follower Signed-off-by: Thomas Citharel --- lib/web/email/group.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/web/email/group.ex b/lib/web/email/group.ex index 964028fc..da29082b 100644 --- a/lib/web/email/group.ex +++ b/lib/web/email/group.ex @@ -11,6 +11,7 @@ defmodule Mobilizon.Web.Email.Group do alias Mobilizon.Events.Event alias Mobilizon.Users.{Setting, User} alias Mobilizon.Web.Email + require Logger @spec notify_of_new_event(Event.t()) :: :ok def notify_of_new_event(%Event{attributed_to: %Actor{} = group} = event) do @@ -63,6 +64,20 @@ defmodule Mobilizon.Web.Email.Group do end end + defp notify_follower( + %Event{uuid: event_uuid}, + %Actor{type: :Group, preferred_username: group_username}, + user + ) do + Logger.warn( + "Unable to notify group follower user #{user.email} for event #{event_uuid} from group #{group_username}" + ) + + :ok + end + + defp notify_follower(_, _, _), do: :ok + @spec accepts_new_events_notifications(list()) :: boolean() defp accepts_new_events_notifications(activity_settings) do case Enum.find(activity_settings, &(&1.key == "event_created" && &1.method == "email")) do