2021-05-06 18:39:59 +02:00
|
|
|
defmodule Mobilizon.Service.Activity.Renderer.Post do
|
|
|
|
@moduledoc """
|
|
|
|
Insert a comment activity
|
|
|
|
"""
|
|
|
|
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)
|
|
|
|
|
2021-06-30 12:09:28 +02:00
|
|
|
%{
|
|
|
|
body:
|
|
|
|
text(activity.subject, %{
|
|
|
|
profile: profile(activity),
|
|
|
|
post: title(activity),
|
|
|
|
group: group(activity)
|
|
|
|
}),
|
|
|
|
url: if(activity.subject !== :post_deleted, do: post_url(activity), else: nil)
|
|
|
|
}
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-30 12:09:28 +02:00
|
|
|
defp text(:post_created, args) do
|
|
|
|
dgettext(
|
|
|
|
"activity",
|
|
|
|
"The post %{post} from group %{group} was published by %{profile}.",
|
|
|
|
args
|
|
|
|
)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-30 12:09:28 +02:00
|
|
|
defp text(:post_updated, args) do
|
|
|
|
dgettext(
|
|
|
|
"activity",
|
|
|
|
"The post %{post} from group %{group} was updated by %{profile}.",
|
|
|
|
args
|
|
|
|
)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-30 12:09:28 +02:00
|
|
|
defp text(:post_deleted, args) do
|
|
|
|
dgettext(
|
|
|
|
"activity",
|
|
|
|
"The post %{post} from group %{group} was deleted by %{profile}.",
|
|
|
|
args
|
|
|
|
)
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|
|
|
|
|
2021-06-30 12:09:28 +02:00
|
|
|
defp post_url(activity) do
|
2023-12-01 09:49:54 +01:00
|
|
|
URI.decode(~p"/p/#{activity.subject_params["post_slug"]}")
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
2021-06-30 12:09:28 +02:00
|
|
|
defp title(activity), do: activity.subject_params["post_title"]
|
|
|
|
defp group(activity), do: Actor.display_name_and_username(activity.group)
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|