2021-05-06 18:39:59 +02:00
|
|
|
defmodule Mobilizon.Service.Activity.Renderer.Member do
|
|
|
|
@moduledoc """
|
|
|
|
Insert a comment activity
|
|
|
|
"""
|
|
|
|
alias Mobilizon.Activities.Activity
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Service.Activity.Renderer
|
2021-07-27 19:47:54 +02:00
|
|
|
alias Mobilizon.Web.Endpoint
|
2021-05-06 18:39:59 +02: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-06-03 15:00:49 +02:00
|
|
|
%{
|
|
|
|
body:
|
|
|
|
text(activity.subject, %{
|
|
|
|
profile: profile(activity),
|
2021-06-30 12:09:28 +02:00
|
|
|
member: member(activity)
|
2021-06-03 15:00:49 +02:00
|
|
|
}),
|
|
|
|
url: member_url(activity)
|
|
|
|
}
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_request, args) do
|
|
|
|
dgettext("activity", "%{member} requested to join the group.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_invited, args) do
|
|
|
|
dgettext("activity", "%{member} was invited by %{profile}.", args)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp text(:member_accepted_invitation, args) do
|
|
|
|
dgettext("activity", "%{member} accepted the invitation to join the group.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_rejected_invitation, args) do
|
|
|
|
dgettext("activity", "%{member} rejected the invitation to join the group.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_joined, args) do
|
|
|
|
dgettext("activity", "%{member} joined the group.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_added, args) do
|
|
|
|
dgettext("activity", "%{profile} added the member %{member}.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-11-12 15:42:52 +01:00
|
|
|
defp text(:member_approved, args) do
|
|
|
|
dgettext("activity", "%{profile} approved the membership request from %{member}.", args)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp text(:member_rejected, args) do
|
|
|
|
dgettext("activity", "%{profile} rejected the membership request from %{member}.", args)
|
|
|
|
end
|
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_updated, args) do
|
|
|
|
dgettext("activity", "%{profile} updated the member %{member}.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_removed, args) do
|
|
|
|
dgettext("activity", "%{profile} excluded member %{member}.", args)
|
|
|
|
end
|
2021-05-06 18:39:59 +02:00
|
|
|
|
2021-06-03 15:00:49 +02:00
|
|
|
defp text(:member_quit, args) do
|
|
|
|
dgettext("activity", "%{profile} quit the group.", args)
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
defp member_url(activity) do
|
2021-06-30 12:09:28 +02:00
|
|
|
group_url =
|
|
|
|
Endpoint
|
|
|
|
|> Routes.page_url(
|
|
|
|
:actor,
|
|
|
|
Actor.preferred_username_and_domain(activity.group)
|
|
|
|
)
|
|
|
|
|> URI.decode()
|
|
|
|
|
|
|
|
"#{group_url}/settings/members"
|
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 member(activity),
|
|
|
|
do:
|
|
|
|
activity.subject_params["member_actor_name"] ||
|
|
|
|
activity.subject_params["member_actor_federated_username"]
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|