2021-05-06 16:39:59 +00:00
|
|
|
defmodule Mobilizon.Service.Activity.Renderer.Group 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)
|
|
|
|
|
|
|
|
case activity.subject do
|
2021-06-30 10:09:28 +00:00
|
|
|
:group_updated ->
|
2021-05-06 16:39:59 +00:00
|
|
|
%{
|
|
|
|
body:
|
2021-06-30 10:09:28 +00:00
|
|
|
dgettext("activity", "The group %{group} was updated by %{profile}.", %{
|
2021-05-06 16:39:59 +00:00
|
|
|
profile: profile(activity),
|
2021-06-30 10:09:28 +00:00
|
|
|
group: group(activity)
|
2021-05-06 16:39:59 +00:00
|
|
|
}),
|
2021-06-30 10:09:28 +00:00
|
|
|
url: group_url(activity)
|
2021-05-06 16:39:59 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-30 10:09:28 +00:00
|
|
|
defp group_url(activity) do
|
2021-06-17 14:19:35 +00:00
|
|
|
Endpoint
|
2021-06-30 10:09:28 +00:00
|
|
|
|> Routes.page_url(:actor, Actor.preferred_username_and_domain(activity.group))
|
2021-06-17 14:19:35 +00:00
|
|
|
|> URI.decode()
|
2021-05-06 16:39:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
2021-06-30 10:09:28 +00:00
|
|
|
defp group(activity), do: Actor.display_name_and_username(activity.group)
|
2021-05-06 16:39:59 +00:00
|
|
|
end
|