4973b529ceec978a4fcd489a20155c00e100ca71
[akkoma] / lib / pleroma / web / push / push.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Push do
6 alias Pleroma.Repo
7 alias Pleroma.Workers.WebPusherWorker
8
9 require Logger
10
11 import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
12
13 def init do
14 unless enabled() do
15 Logger.warn("""
16 VAPID key pair is not found. If you wish to enabled web push, please run
17
18 mix web_push.gen.keypair
19
20 and add the resulting output to your configuration file.
21 """)
22 end
23 end
24
25 def vapid_config do
26 Application.get_env(:web_push_encryption, :vapid_details, [])
27 end
28
29 def enabled do
30 case vapid_config() do
31 [] -> false
32 list when is_list(list) -> true
33 _ -> false
34 end
35 end
36
37 def send(notification) do
38 %{"op" => "web_push", "notification_id" => notification.id}
39 |> WebPusherWorker.new(worker_args(:web_push))
40 |> Repo.insert()
41 end
42 end