feat(notifications): add missing notifications when an user registers to an event

Closes #1344

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-08-24 11:42:03 +02:00
parent f99267c611
commit da532c7059
15 changed files with 149 additions and 15 deletions

View File

@@ -4,7 +4,17 @@ defmodule Mobilizon.Service.Activity do
"""
alias Mobilizon.Activities.Activity
alias Mobilizon.Service.Activity.{Comment, Discussion, Event, Group, Member, Post, Resource}
alias Mobilizon.Service.Activity.{
Comment,
Discussion,
Event,
Group,
Member,
Participant,
Post,
Resource
}
@callback insert_activity(entity :: struct(), options :: Keyword.t()) ::
{:ok, Oban.Job.t()} | {:ok, any()} | {:error, Ecto.Changeset.t()}
@@ -45,4 +55,8 @@ defmodule Mobilizon.Service.Activity do
defp do_get_object(:comment, comment_id) do
Comment.get_object(comment_id)
end
defp do_get_object(:participant, participant_id) do
Participant.get_object(participant_id)
end
end

View File

@@ -0,0 +1,48 @@
defmodule Mobilizon.Service.Activity.Participant do
@moduledoc """
Insert an event activity
"""
alias Mobilizon.{Actors, Events}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events.Participant
alias Mobilizon.Service.Activity
alias Mobilizon.Service.Workers.ActivityBuilder
@behaviour Activity
@impl Activity
def insert_activity(event, options \\ [])
def insert_activity(
%Participant{event_id: event_id, actor_id: actor_id, id: participant_id} =
_participant,
options
) do
actor = Actors.get_actor(actor_id)
event = Events.get_event!(event_id)
subject = Keyword.fetch!(options, :subject)
ActivityBuilder.enqueue(:build_activity, %{
"type" => "event",
"subject" => subject,
"subject_params" => %{
actor_name: Actor.display_name(actor),
event_title: event.title,
event_uuid: event.uuid
},
"group_id" => event.attributed_to_id,
"author_id" => actor.id,
"object_type" => "participant",
"object_id" => participant_id,
"inserted_at" => DateTime.utc_now()
})
end
@impl Activity
def insert_activity(_, _), do: {:ok, nil}
@impl Activity
def get_object(participant_id) do
Events.get_participant(participant_id)
end
end

View File

@@ -1,6 +1,6 @@
defmodule Mobilizon.Service.Activity.Renderer.Event do
@moduledoc """
Insert a comment activity
Insert an event activity
"""
alias Mobilizon.Activities.Activity
alias Mobilizon.Actors.Actor
@@ -67,6 +67,16 @@ defmodule Mobilizon.Service.Activity.Renderer.Event do
url: event_url(activity)
}
end
:event_new_participation ->
%{
body:
dgettext("activity", "%{profile} joined your event %{event}.", %{
profile: profile(activity),
event: title(activity)
}),
url: event_url(activity)
}
end
end

View File

@@ -96,7 +96,7 @@ defmodule Mobilizon.Service.Notifier.Email do
defp can_send_activity?(activity, user, options) do
Logger.warning(
"Can't check if user #{inspect(user)} can be sent an activity (#{inspect(activity)}) (#{inspect(options)})"
"Can't check if user #{inspect(user.email)} can be sent an activity (#{inspect(activity)}) (#{inspect(options)})"
)
false