logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

push.ex (957B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Push do
  5. alias Pleroma.Workers.WebPusherWorker
  6. require Logger
  7. def init do
  8. unless enabled() do
  9. Logger.warning("""
  10. VAPID key pair is not found. If you wish to enabled web push, please run
  11. mix web_push.gen.keypair
  12. and add the resulting output to your configuration file.
  13. """)
  14. end
  15. end
  16. def vapid_config do
  17. Application.get_env(:web_push_encryption, :vapid_details, [])
  18. end
  19. def enabled, do: match?([subject: _, public_key: _, private_key: _], vapid_config())
  20. @spec send(Pleroma.Notification.t()) ::
  21. {:ok, Oban.Job.t()} | {:error, Oban.Job.changeset() | term()}
  22. def send(notification) do
  23. WebPusherWorker.new(%{"op" => "web_push", "notification_id" => notification.id})
  24. |> Oban.insert()
  25. end
  26. end