[#1149] Added Oban job for "activity_expiration". Merged remote-tracking branch ...
[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.WebPusher
8
9 require Logger
10
11 defdelegate worker_args(queue), to: Pleroma.Workers.Helper
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 |> WebPusher.new(worker_args(:web_push))
40 |> Repo.insert()
41 end
42 end