2018-12-23 20:04:54 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 20:04:54 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
2018-12-06 19:29:04 +07:00
|
|
|
defmodule Pleroma.Web.Push do
|
2019-08-31 19:08:56 +03:00
|
|
|
alias Pleroma.Workers.WebPusherWorker
|
2018-12-06 19:29:04 +07:00
|
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
|
2019-04-05 19:46:28 +07:00
|
|
|
def init do
|
2019-04-05 19:38:44 +07:00
|
|
|
unless enabled() do
|
2023-11-28 17:17:46 +00:00
|
|
|
Logger.warning("""
|
2019-04-05 19:38:44 +07:00
|
|
|
VAPID key pair is not found. If you wish to enabled web push, please run
|
|
|
|
|
|
|
|
|
|
mix web_push.gen.keypair
|
2018-12-06 19:29:04 +07:00
|
|
|
|
2019-04-05 19:38:44 +07:00
|
|
|
and add the resulting output to your configuration file.
|
|
|
|
|
""")
|
|
|
|
|
end
|
2018-12-06 19:29:04 +07:00
|
|
|
end
|
|
|
|
|
|
2019-03-05 04:18:43 +01:00
|
|
|
def vapid_config do
|
2024-09-24 05:54:25 +02:00
|
|
|
Application.get_env(:web_push_encryption, :vapid_details, [])
|
2018-12-09 13:45:21 +01:00
|
|
|
end
|
2018-12-06 19:29:04 +07:00
|
|
|
|
2024-06-08 18:59:51 -04:00
|
|
|
def enabled, do: match?([subject: _, public_key: _, private_key: _], vapid_config())
|
2018-12-06 19:29:04 +07:00
|
|
|
|
2024-06-08 19:20:38 -04:00
|
|
|
@spec send(Pleroma.Notification.t()) ::
|
|
|
|
|
{:ok, Oban.Job.t()} | {:error, Oban.Job.changeset() | term()}
|
2019-08-13 20:20:26 +03:00
|
|
|
def send(notification) do
|
2024-06-28 11:47:31 -04:00
|
|
|
WebPusherWorker.new(%{"op" => "web_push", "notification_id" => notification.id})
|
2024-08-07 13:00:31 -04:00
|
|
|
|> Oban.insert()
|
2019-08-13 20:20:26 +03:00
|
|
|
end
|
2018-12-06 19:29:04 +07:00
|
|
|
end
|