Add context param to push route
This commit is contained in:
parent
26c0d2565b
commit
4781e6d789
|
@ -4,8 +4,9 @@ defmodule TuskerPush.Forwarder do
|
|||
|
||||
require Logger
|
||||
|
||||
@spec forward(Registration.t(), binary(), String.t(), String.t()) :: :ok | {:error, term()}
|
||||
def forward(%Registration{push_version: 1} = registration, body, salt, key) do
|
||||
@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" => %{
|
||||
|
@ -20,6 +21,13 @@ defmodule TuskerPush.Forwarder do
|
|||
"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)
|
||||
|
|
|
@ -4,7 +4,7 @@ defmodule TuskerPushWeb.PushController do
|
|||
|
||||
require Logger
|
||||
|
||||
def push(conn, %{"id" => id}) do
|
||||
def push(conn, %{"id" => id} = params) do
|
||||
with {:registration, registration} when not is_nil(registration) <-
|
||||
{:registration, TuskerPush.get_registration(id)},
|
||||
:ok <- TuskerPush.check_registration_expired(registration),
|
||||
|
@ -12,7 +12,8 @@ defmodule TuskerPushWeb.PushController do
|
|||
{:body, {:ok, body, conn}} <- {:body, read_body(conn)},
|
||||
{:salt, salt} when not is_nil(salt) <- get_salt(conn),
|
||||
{:key, key} when not is_nil(key) <- get_key(conn),
|
||||
{:forward, :ok} <- {:forward, Forwarder.forward(registration, body, salt, key)} do
|
||||
context <- Map.get(params, "context"),
|
||||
{:forward, :ok} <- {:forward, Forwarder.forward(registration, body, salt, key, context)} do
|
||||
send_resp(conn, 200, "ok")
|
||||
else
|
||||
{:registration, nil} ->
|
||||
|
|
Loading…
Reference in New Issue