set alert types in compile time

This commit is contained in:
Alexander Strizhakov 2020-06-17 18:39:20 +03:00
parent a74d0f8b27
commit 46492a2aee
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381

View File

@ -14,6 +14,8 @@ defmodule Pleroma.Web.Push.Subscription do
@type t :: %__MODULE__{} @type t :: %__MODULE__{}
@supported_alert_types Enum.map(Pleroma.Notification.types(), &String.to_atom/1)
schema "push_subscriptions" do schema "push_subscriptions" do
belongs_to(:user, User, type: FlakeId.Ecto.CompatType) belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
belongs_to(:token, Token) belongs_to(:token, Token)
@ -29,8 +31,7 @@ defmodule Pleroma.Web.Push.Subscription do
@supported_alert_types ~w[follow favourite mention reblog pleroma:chat_mention pleroma:emoji_reaction]a @supported_alert_types ~w[follow favourite mention reblog pleroma:chat_mention pleroma:emoji_reaction]a
defp alerts(%{data: %{alerts: alerts}}) do defp alerts(%{data: %{alerts: alerts}}) do
types = Enum.map(Pleroma.Notification.types(), &String.to_atom/1) alerts = Map.take(alerts, @supported_alert_types)
alerts = Map.take(alerts, types)
%{"alerts" => alerts} %{"alerts" => alerts}
end end