2021-05-06 18:39:59 +02:00
|
|
|
defmodule Mobilizon.Service.Activity.Renderer.Event do
|
|
|
|
@moduledoc """
|
2023-08-24 11:42:03 +02:00
|
|
|
Insert an event activity
|
2021-05-06 18:39:59 +02:00
|
|
|
"""
|
|
|
|
alias Mobilizon.Activities.Activity
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Service.Activity.Renderer
|
2023-12-01 09:49:54 +01:00
|
|
|
use Mobilizon.Web, :verified_routes
|
2021-05-06 18:39:59 +02:00
|
|
|
import Mobilizon.Web.Gettext, only: [dgettext: 3]
|
|
|
|
|
|
|
|
@behaviour Renderer
|
|
|
|
|
|
|
|
@impl Renderer
|
|
|
|
def render(%Activity{} = activity, options) do
|
|
|
|
locale = Keyword.get(options, :locale, "en")
|
|
|
|
Gettext.put_locale(locale)
|
|
|
|
|
|
|
|
case activity.subject do
|
|
|
|
:event_created ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "The event %{event} was created by %{profile}.", %{
|
|
|
|
profile: profile(activity),
|
|
|
|
event: title(activity)
|
|
|
|
}),
|
|
|
|
url: event_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:event_updated ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "The event %{event} was updated by %{profile}.", %{
|
|
|
|
profile: profile(activity),
|
|
|
|
event: title(activity)
|
|
|
|
}),
|
|
|
|
url: event_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:event_deleted ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "The event %{event} was deleted by %{profile}.", %{
|
|
|
|
profile: profile(activity),
|
|
|
|
event: title(activity)
|
|
|
|
}),
|
|
|
|
url: nil
|
|
|
|
}
|
|
|
|
|
|
|
|
:comment_posted ->
|
|
|
|
if activity.subject_params["comment_reply_to"] do
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} replied to a comment on the event %{event}.", %{
|
|
|
|
profile: profile(activity),
|
|
|
|
event: title(activity)
|
|
|
|
}),
|
|
|
|
url: event_url(activity)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} posted a comment on the event %{event}.", %{
|
|
|
|
profile: profile(activity),
|
|
|
|
event: title(activity)
|
|
|
|
}),
|
|
|
|
url: event_url(activity)
|
|
|
|
}
|
|
|
|
end
|
2023-08-24 11:42:03 +02:00
|
|
|
|
|
|
|
:event_new_participation ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} joined your event %{event}.", %{
|
|
|
|
profile: profile(activity),
|
|
|
|
event: title(activity)
|
|
|
|
}),
|
|
|
|
url: event_url(activity)
|
|
|
|
}
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp event_url(activity) do
|
2023-12-01 09:49:54 +01:00
|
|
|
~p"/events/#{activity.subject_params["event_uuid"]}"
|
|
|
|
|> url()
|
2021-06-17 16:19:35 +02:00
|
|
|
|> URI.decode()
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
|
|
|
defp title(activity), do: activity.subject_params["event_title"]
|
|
|
|
end
|