Add version to registration
This commit is contained in:
parent
47d2334d4d
commit
257ea3e47e
|
@ -3,7 +3,7 @@ defmodule TuskerPush.Forwarder do
|
|||
alias TuskerPush.Registration
|
||||
|
||||
@spec forward(Registration.t(), binary(), String.t(), String.t()) :: :ok | {:error, term()}
|
||||
def forward(registration, body, salt, key) do
|
||||
def forward(%Registration{push_version: 1} = registration, body, salt, key) do
|
||||
payload = %{
|
||||
"aps" => %{
|
||||
"alert" => %{
|
||||
|
@ -14,7 +14,8 @@ defmodule TuskerPush.Forwarder do
|
|||
"reg_id" => registration.id,
|
||||
"data" => Base.encode64(body),
|
||||
"salt" => salt,
|
||||
"pk" => key
|
||||
"pk" => key,
|
||||
"v" => 1
|
||||
}
|
||||
|
||||
Apns.send(registration, payload)
|
||||
|
|
|
@ -8,6 +8,7 @@ defmodule TuskerPush.Registration do
|
|||
storekit_original_transaction_id: String.t(),
|
||||
apns_environment: String.t(),
|
||||
apns_device_token: String.t(),
|
||||
push_version: integer(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
}
|
||||
|
@ -21,10 +22,17 @@ defmodule TuskerPush.Registration do
|
|||
# hex-encoded
|
||||
field :apns_device_token, :string
|
||||
|
||||
field :push_version, :integer
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@required_fields [:storekit_original_transaction_id, :apns_environment, :apns_device_token]
|
||||
@required_fields [
|
||||
:storekit_original_transaction_id,
|
||||
:apns_environment,
|
||||
:apns_device_token,
|
||||
:push_version
|
||||
]
|
||||
|
||||
def create_changeset(registration \\ %__MODULE__{}, params) do
|
||||
registration
|
||||
|
|
|
@ -8,13 +8,15 @@ defmodule TuskerPushWeb.RegistrationsController do
|
|||
def create(conn, %{
|
||||
"transaction_id" => transaction_id,
|
||||
"environment" => env,
|
||||
"device_token" => token
|
||||
"device_token" => token,
|
||||
"push_version" => version
|
||||
}) do
|
||||
with {:ok, %Registration{id: id}} <-
|
||||
TuskerPush.register(%{
|
||||
storekit_original_transaction_id: transaction_id,
|
||||
apns_environment: env,
|
||||
apns_device_token: token
|
||||
apns_device_token: token,
|
||||
push_version: version
|
||||
}) do
|
||||
conn
|
||||
|> json(%{
|
||||
|
|
|
@ -10,6 +10,8 @@ defmodule TuskerPush.Repo.Migrations.CreateRegistrations do
|
|||
add :apns_environment, :string, null: false
|
||||
add :apns_device_token, :string, null: false
|
||||
|
||||
add :push_version, :integer, null: false
|
||||
|
||||
timestamps()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue