2021-05-06 16:39:59 +00:00
|
|
|
defmodule Mobilizon.Service.Activity.Renderer.Resource do
|
|
|
|
@moduledoc """
|
|
|
|
Insert a comment activity
|
|
|
|
"""
|
|
|
|
alias Mobilizon.Activities.Activity
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Service.Activity.Renderer
|
2021-07-27 17:47:54 +00:00
|
|
|
alias Mobilizon.Web.Endpoint
|
2021-05-06 16:39:59 +00:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
|
|
|
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-11-17 15:25:21 +00:00
|
|
|
%{
|
|
|
|
body:
|
|
|
|
text(activity.subject, %{
|
|
|
|
profile: profile(activity),
|
|
|
|
resource: title(activity),
|
|
|
|
group: group(activity),
|
|
|
|
subject_params: activity.subject_params
|
|
|
|
}),
|
|
|
|
resource_url: resource_url(activity)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp text(:resource_created, %{subject_params: subject_params} = args) do
|
|
|
|
if subject_params["is_folder"] do
|
|
|
|
dgettext("activity", "%{profile} created the folder %{resource} in group %{group}.", args)
|
|
|
|
else
|
|
|
|
dgettext(
|
|
|
|
"activity",
|
|
|
|
"%{profile} created the resource %{resource} in group %{group}.",
|
|
|
|
args
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2021-05-06 16:39:59 +00:00
|
|
|
|
2021-11-17 15:25:21 +00:00
|
|
|
defp text(:resource_renamed, %{subject_params: subject_params} = args) do
|
|
|
|
if subject_params["is_folder"] do
|
|
|
|
dgettext(
|
|
|
|
"activity",
|
|
|
|
"%{profile} renamed the folder from %{old_resource_title} to %{resource} in group %{group}.",
|
|
|
|
Map.put(args, :old_resource_title, subject_params["old_resource_title"])
|
|
|
|
)
|
|
|
|
else
|
|
|
|
dgettext(
|
|
|
|
"activity",
|
|
|
|
"%{profile} renamed the resource from %{old_resource_title} to %{resource} in group %{group}.",
|
|
|
|
Map.put(args, :old_resource_title, subject_params["old_resource_title"])
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2021-05-06 16:39:59 +00:00
|
|
|
|
2021-11-17 15:25:21 +00:00
|
|
|
defp text(:resource_moved, %{subject_params: subject_params} = args) do
|
|
|
|
if subject_params["is_folder"] do
|
|
|
|
dgettext("activity", "%{profile} moved the folder %{resource} in group %{group}.", args)
|
|
|
|
else
|
|
|
|
dgettext("activity", "%{profile} moved the resource %{resource} in group %{group}.", args)
|
|
|
|
end
|
|
|
|
end
|
2021-05-06 16:39:59 +00:00
|
|
|
|
2021-11-17 15:25:21 +00:00
|
|
|
defp text(:resource_deleted, %{subject_params: subject_params} = args) do
|
|
|
|
if subject_params["is_folder"] do
|
|
|
|
dgettext("activity", "%{profile} deleted the folder %{resource} in group %{group}.", args)
|
|
|
|
else
|
|
|
|
dgettext("activity", "%{profile} deleted the resource %{resource} in group %{group}.", args)
|
2021-05-06 16:39:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp resource_url(activity) do
|
2021-06-17 14:19:35 +00:00
|
|
|
Endpoint
|
|
|
|
|> Routes.page_url(:resource, activity.subject_params["resource_uuid"])
|
|
|
|
|> URI.decode()
|
2021-05-06 16:39:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
|
|
|
defp title(activity), do: activity.subject_params["resource_title"]
|
2021-11-17 15:25:21 +00:00
|
|
|
defp group(%Activity{group: group}), do: Actor.display_name(group)
|
2021-05-06 16:39:59 +00:00
|
|
|
end
|