Merge develop
[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.Workers.WebPusherWorker
7
8 require Logger
9
10 def init do
11 unless enabled() do
12 Logger.warn("""
13 VAPID key pair is not found. If you wish to enabled web push, please run
14
15 mix web_push.gen.keypair
16
17 and add the resulting output to your configuration file.
18 """)
19 end
20 end
21
22 def vapid_config do
23 Application.get_env(:web_push_encryption, :vapid_details, [])
24 end
25
26 def enabled do
27 case vapid_config() do
28 [] -> false
29 list when is_list(list) -> true
30 _ -> false
31 end
32 end
33
34 def send(notification) do
35 WebPusherWorker.enqueue("web_push", %{"notification_id" => notification.id})
36 end
37 end