Fix push notifications for group, members & post activities
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -17,44 +17,24 @@ defmodule Mobilizon.Service.Activity.Renderer.Group do
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
case activity.subject do
|
||||
:post_created ->
|
||||
:group_updated ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "The post %{post} was created by %{profile}.", %{
|
||||
dgettext("activity", "The group %{group} was updated by %{profile}.", %{
|
||||
profile: profile(activity),
|
||||
post: title(activity)
|
||||
group: group(activity)
|
||||
}),
|
||||
url: post_url(activity)
|
||||
}
|
||||
|
||||
:post_updated ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "The post %{post} was updated by %{profile}.", %{
|
||||
profile: profile(activity),
|
||||
post: title(activity)
|
||||
}),
|
||||
url: post_url(activity)
|
||||
}
|
||||
|
||||
:post_deleted ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "The post %{post} was deleted by %{profile}.", %{
|
||||
profile: profile(activity),
|
||||
post: title(activity)
|
||||
}),
|
||||
url: post_url(activity)
|
||||
url: group_url(activity)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
defp post_url(activity) do
|
||||
defp group_url(activity) do
|
||||
Endpoint
|
||||
|> Routes.page_url(:post, activity.subject_params["post_slug"])
|
||||
|> Routes.page_url(:actor, Actor.preferred_username_and_domain(activity.group))
|
||||
|> URI.decode()
|
||||
end
|
||||
|
||||
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
||||
defp title(activity), do: activity.subject_params["post_title"]
|
||||
defp group(activity), do: Actor.display_name_and_username(activity.group)
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Member do
|
||||
body:
|
||||
text(activity.subject, %{
|
||||
profile: profile(activity),
|
||||
member: title(activity)
|
||||
member: member(activity)
|
||||
}),
|
||||
url: member_url(activity)
|
||||
}
|
||||
@@ -63,15 +63,21 @@ defmodule Mobilizon.Service.Activity.Renderer.Member do
|
||||
end
|
||||
|
||||
defp member_url(activity) do
|
||||
Endpoint
|
||||
|> Routes.page_url(
|
||||
:discussion,
|
||||
Actor.preferred_username_and_domain(activity.group),
|
||||
activity.subject_params["discussion_slug"]
|
||||
)
|
||||
|> URI.decode()
|
||||
group_url =
|
||||
Endpoint
|
||||
|> Routes.page_url(
|
||||
:actor,
|
||||
Actor.preferred_username_and_domain(activity.group)
|
||||
)
|
||||
|> URI.decode()
|
||||
|
||||
"#{group_url}/settings/members"
|
||||
end
|
||||
|
||||
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
||||
defp title(activity), do: activity.subject_params["discussion_title"]
|
||||
|
||||
defp member(activity),
|
||||
do:
|
||||
activity.subject_params["member_actor_name"] ||
|
||||
activity.subject_params["member_actor_federated_username"]
|
||||
end
|
||||
|
||||
@@ -16,69 +16,51 @@ defmodule Mobilizon.Service.Activity.Renderer.Post do
|
||||
locale = Keyword.get(options, :locale, "en")
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
case activity.subject do
|
||||
:discussion_created ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "%{profile} created the discussion %{discussion}.", %{
|
||||
profile: profile(activity),
|
||||
discussion: title(activity)
|
||||
}),
|
||||
url: discussion_url(activity)
|
||||
}
|
||||
|
||||
:discussion_replied ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "%{profile} replied to the discussion %{discussion}.", %{
|
||||
profile: profile(activity),
|
||||
discussion: title(activity)
|
||||
}),
|
||||
url: discussion_url(activity)
|
||||
}
|
||||
|
||||
:discussion_renamed ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "%{profile} renamed the discussion %{discussion}.", %{
|
||||
profile: profile(activity),
|
||||
discussion: title(activity)
|
||||
}),
|
||||
url: discussion_url(activity)
|
||||
}
|
||||
|
||||
:discussion_archived ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "%{profile} archived the discussion %{discussion}.", %{
|
||||
profile: profile(activity),
|
||||
discussion: title(activity)
|
||||
}),
|
||||
url: discussion_url(activity)
|
||||
}
|
||||
|
||||
:discussion_deleted ->
|
||||
%{
|
||||
body:
|
||||
dgettext("activity", "%{profile} deleted the discussion %{discussion}.", %{
|
||||
profile: profile(activity),
|
||||
discussion: title(activity)
|
||||
}),
|
||||
url: nil
|
||||
}
|
||||
end
|
||||
%{
|
||||
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
|
||||
|
||||
defp discussion_url(activity) do
|
||||
defp text(:post_created, args) do
|
||||
dgettext(
|
||||
"activity",
|
||||
"The post %{post} from group %{group} was published by %{profile}.",
|
||||
args
|
||||
)
|
||||
end
|
||||
|
||||
defp text(:post_updated, args) do
|
||||
dgettext(
|
||||
"activity",
|
||||
"The post %{post} from group %{group} was updated by %{profile}.",
|
||||
args
|
||||
)
|
||||
end
|
||||
|
||||
defp text(:post_deleted, args) do
|
||||
dgettext(
|
||||
"activity",
|
||||
"The post %{post} from group %{group} was deleted by %{profile}.",
|
||||
args
|
||||
)
|
||||
end
|
||||
|
||||
defp post_url(activity) do
|
||||
Endpoint
|
||||
|> Routes.page_url(
|
||||
:discussion,
|
||||
Actor.preferred_username_and_domain(activity.group),
|
||||
activity.subject_params["discussion_slug"]
|
||||
:post,
|
||||
activity.subject_params["post_slug"]
|
||||
)
|
||||
|> URI.decode()
|
||||
end
|
||||
|
||||
defp profile(activity), do: Actor.display_name_and_username(activity.author)
|
||||
defp title(activity), do: activity.subject_params["discussion_title"]
|
||||
defp title(activity), do: activity.subject_params["post_title"]
|
||||
defp group(activity), do: Actor.display_name_and_username(activity.group)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user