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
|
require Logger
|
||||||
|
|
||||||
@spec forward(Registration.t(), binary(), String.t(), String.t()) :: :ok | {:error, term()}
|
@spec forward(Registration.t(), binary(), String.t(), String.t(), String.t() | nil) ::
|
||||||
def forward(%Registration{push_version: 1} = registration, body, salt, key) do
|
:ok | {:error, term()}
|
||||||
|
def forward(%Registration{push_version: 1} = registration, body, salt, key, context) do
|
||||||
payload = %{
|
payload = %{
|
||||||
"aps" => %{
|
"aps" => %{
|
||||||
"alert" => %{
|
"alert" => %{
|
||||||
|
@ -20,6 +21,13 @@ defmodule TuskerPush.Forwarder do
|
||||||
"v" => 1
|
"v" => 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload =
|
||||||
|
unless is_nil(context) do
|
||||||
|
Map.put(payload, "ctx", context)
|
||||||
|
else
|
||||||
|
payload
|
||||||
|
end
|
||||||
|
|
||||||
Logger.debug("Sending #{inspect(payload)}")
|
Logger.debug("Sending #{inspect(payload)}")
|
||||||
|
|
||||||
Apns.send(registration, payload)
|
Apns.send(registration, payload)
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule TuskerPushWeb.PushController do
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def push(conn, %{"id" => id}) do
|
def push(conn, %{"id" => id} = params) do
|
||||||
with {:registration, registration} when not is_nil(registration) <-
|
with {:registration, registration} when not is_nil(registration) <-
|
||||||
{:registration, TuskerPush.get_registration(id)},
|
{:registration, TuskerPush.get_registration(id)},
|
||||||
:ok <- TuskerPush.check_registration_expired(registration),
|
:ok <- TuskerPush.check_registration_expired(registration),
|
||||||
|
@ -12,7 +12,8 @@ defmodule TuskerPushWeb.PushController do
|
||||||
{:body, {:ok, body, conn}} <- {:body, read_body(conn)},
|
{:body, {:ok, body, conn}} <- {:body, read_body(conn)},
|
||||||
{:salt, salt} when not is_nil(salt) <- get_salt(conn),
|
{:salt, salt} when not is_nil(salt) <- get_salt(conn),
|
||||||
{:key, key} when not is_nil(key) <- get_key(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")
|
send_resp(conn, 200, "ok")
|
||||||
else
|
else
|
||||||
{:registration, nil} ->
|
{:registration, nil} ->
|
||||||
|
|
Loading…
Reference in New Issue