2021-05-06 18:39:59 +02:00
|
|
|
defmodule Mobilizon.Service.Activity.Renderer.Discussion 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-23 19:49:10 +02:00
|
|
|
profile = profile(activity)
|
|
|
|
title = title(activity)
|
2021-05-06 18:39:59 +02:00
|
|
|
|
|
|
|
case activity.subject do
|
|
|
|
:discussion_created ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} created the discussion %{discussion}.", %{
|
2021-06-23 19:49:10 +02:00
|
|
|
profile: profile,
|
|
|
|
discussion: title
|
2021-05-06 18:39:59 +02:00
|
|
|
}),
|
|
|
|
url: discussion_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:discussion_replied ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} replied to the discussion %{discussion}.", %{
|
2021-06-23 19:49:10 +02:00
|
|
|
profile: profile,
|
|
|
|
discussion: title
|
|
|
|
}),
|
|
|
|
url: discussion_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:discussion_mention ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} mentionned you in the discussion %{discussion}.", %{
|
|
|
|
profile: profile,
|
|
|
|
discussion: title
|
2021-05-06 18:39:59 +02:00
|
|
|
}),
|
|
|
|
url: discussion_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:discussion_renamed ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} renamed the discussion %{discussion}.", %{
|
2021-06-23 19:49:10 +02:00
|
|
|
profile: profile,
|
|
|
|
discussion: title
|
2021-05-06 18:39:59 +02:00
|
|
|
}),
|
|
|
|
url: discussion_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:discussion_archived ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} archived the discussion %{discussion}.", %{
|
2021-06-23 19:49:10 +02:00
|
|
|
profile: profile,
|
|
|
|
discussion: title
|
2021-05-06 18:39:59 +02:00
|
|
|
}),
|
|
|
|
url: discussion_url(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
:discussion_deleted ->
|
|
|
|
%{
|
|
|
|
body:
|
|
|
|
dgettext("activity", "%{profile} deleted the discussion %{discussion}.", %{
|
2021-06-23 19:49:10 +02:00
|
|
|
profile: profile,
|
|
|
|
discussion: title
|
2021-05-06 18:39:59 +02:00
|
|
|
}),
|
|
|
|
url: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp discussion_url(activity) do
|
2021-06-17 16:19:35 +02:00
|
|
|
Endpoint
|
|
|
|
|> Routes.page_url(
|
2021-05-06 18:39:59 +02:00
|
|
|
:discussion,
|
|
|
|
Actor.preferred_username_and_domain(activity.group),
|
|
|
|
activity.subject_params["discussion_slug"]
|
|
|
|
)
|
2021-06-17 16:19:35 +02:00
|
|
|
|> URI.decode()
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|
|
|
|
|
2021-06-23 19:49:10 +02:00
|
|
|
defp profile(%Activity{author: author}), do: Actor.display_name_and_username(author)
|
|
|
|
|
|
|
|
defp title(%Activity{subject_params: %{"discussion_title" => discussion_title}}),
|
|
|
|
do: discussion_title
|
2021-05-06 18:39:59 +02:00
|
|
|
end
|