36 lines
819 B
Elixir
36 lines
819 B
Elixir
defmodule TuskerPush.Forwarder do
|
|
alias TuskerPush.Apns
|
|
alias TuskerPush.Registration
|
|
|
|
require Logger
|
|
|
|
@spec forward(Registration.t(), binary(), String.t(), String.t(), String.t() | nil) ::
|
|
:ok | {:error, term()}
|
|
def forward(%Registration{push_version: 1} = registration, body, salt, key, context) do
|
|
payload = %{
|
|
"aps" => %{
|
|
"alert" => %{
|
|
"loc-key" => "apns_enc"
|
|
},
|
|
"mutable-content" => 1
|
|
},
|
|
"reg_id" => registration.id,
|
|
"data" => Base.encode64(body),
|
|
"salt" => salt,
|
|
"pk" => key,
|
|
"v" => 1
|
|
}
|
|
|
|
payload =
|
|
unless is_nil(context) do
|
|
Map.put(payload, "ctx", context)
|
|
else
|
|
payload
|
|
end
|
|
|
|
Logger.debug("Sending #{inspect(payload)}")
|
|
|
|
Apns.send(registration, payload)
|
|
end
|
|
end
|