Render nice web push notifications for polls

This commit is contained in:
Mark Felder 2024-06-08 20:30:43 -04:00
commit 3211557f74
4 changed files with 42 additions and 0 deletions

View file

@ -130,6 +130,24 @@ defmodule Pleroma.Web.Push.Impl do
end
end
def format_body(
%{type: "poll"} = _notification,
_user,
%{data: %{"content" => content} = data} = _object
) do
options = Map.get(data, "anyOf") || Map.get(data, "oneOf")
content_text = content <> "\n"
options_text =
Enum.map(options, fn x -> "#{x["name"]}" end)
|> Enum.join("\n")
[content_text, options_text]
|> Enum.join("\n")
|> Utils.scrub_html_and_truncate(80)
end
def format_body(
%{activity: %{data: %{"type" => "Create"}}},
user,
@ -191,6 +209,7 @@ defmodule Pleroma.Web.Push.Impl do
"update" -> "New Update"
"pleroma:chat_mention" -> "New Chat Message"
"pleroma:emoji_reaction" -> "New Reaction"
"poll" -> "Poll Results"
type -> "New #{String.capitalize(type || "event")}"
end
end