Send notifications to event organizer when new comment is posted

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-06-27 11:21:34 +02:00
parent 93297931bb
commit 3ed25bab81
9 changed files with 161 additions and 64 deletions

View File

@@ -159,10 +159,11 @@ defmodule Mobilizon.Service.Activity.Comment do
%Comment{
actor_id: actor_id,
in_reply_to_comment_id: in_reply_to_comment_id,
id: comment_id
},
id: comment_id,
uuid: comment_uuid
} = comment,
%Event{
uuid: uuid,
uuid: event_uuid,
title: title,
attributed_to: nil,
organizer_actor_id: organizer_actor_id
@@ -174,8 +175,10 @@ defmodule Mobilizon.Service.Activity.Comment do
"subject" => :event_new_comment,
"subject_params" => %{
event_title: title,
event_uuid: uuid,
comment_reply_to: !is_nil(in_reply_to_comment_id)
event_uuid: event_uuid,
comment_reply_to: !is_nil(in_reply_to_comment_id),
comment_uuid: comment_uuid,
comment_reply_to_uuid: reply_to_comment_uuid(comment)
},
"author_id" => actor_id,
"object_id" => to_string(comment_id)
@@ -185,4 +188,10 @@ defmodule Mobilizon.Service.Activity.Comment do
end
defp notify(_, _, _, _), do: {:ok, :skipped}
@spec reply_to_comment_uuid(Comment.t()) :: String.t() | nil
defp reply_to_comment_uuid(%Comment{in_reply_to_comment: %Comment{uuid: comment_reply_to_uuid}}),
do: comment_reply_to_uuid
defp reply_to_comment_uuid(%Comment{in_reply_to_comment: _}), do: nil
end

View File

@@ -45,6 +45,35 @@ defmodule Mobilizon.Service.Activity.Renderer.Comment do
),
url: event_url(activity)
}
:event_new_comment ->
if activity.subject_params["comment_reply_to"] do
%{
body:
dgettext(
"activity",
"%{profile} has posted a new reply under your event %{event}.",
%{
profile: profile,
event: event_title(activity)
}
),
url: event_comment_url(activity)
}
else
%{
body:
dgettext(
"activity",
"%{profile} has posted a new comment under your event %{event}.",
%{
profile: profile,
event: event_title(activity)
}
),
url: event_comment_url(activity)
}
end
end
end
@@ -56,6 +85,18 @@ defmodule Mobilizon.Service.Activity.Renderer.Comment do
)
end
defp event_comment_url(activity) do
"#{event_url(activity)}#comment-#{comment_uuid(activity)}"
end
defp comment_uuid(activity) do
if activity.subject_params["comment_reply_to"] do
"#{activity.subject_params["reply_to_comment_uuid"]}-#{activity.subject_params["comment_uuid"]}"
else
activity.subject_params["comment_uuid"]
end
end
defp profile(activity), do: Actor.display_name_and_username(activity.author)
defp event_title(activity), do: activity.subject_params["event_title"]
end