Add version to registration

This commit is contained in:
Shadowfacts 2024-04-06 15:26:44 -04:00
parent 47d2334d4d
commit 257ea3e47e
4 changed files with 18 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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(%{

View File

@ -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