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 alias TuskerPush.Registration
@spec forward(Registration.t(), binary(), String.t(), String.t()) :: :ok | {:error, term()} @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 = %{ payload = %{
"aps" => %{ "aps" => %{
"alert" => %{ "alert" => %{
@ -14,7 +14,8 @@ defmodule TuskerPush.Forwarder do
"reg_id" => registration.id, "reg_id" => registration.id,
"data" => Base.encode64(body), "data" => Base.encode64(body),
"salt" => salt, "salt" => salt,
"pk" => key "pk" => key,
"v" => 1
} }
Apns.send(registration, payload) Apns.send(registration, payload)

View File

@ -8,6 +8,7 @@ defmodule TuskerPush.Registration do
storekit_original_transaction_id: String.t(), storekit_original_transaction_id: String.t(),
apns_environment: String.t(), apns_environment: String.t(),
apns_device_token: String.t(), apns_device_token: String.t(),
push_version: integer(),
inserted_at: NaiveDateTime.t(), inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t() updated_at: NaiveDateTime.t()
} }
@ -21,10 +22,17 @@ defmodule TuskerPush.Registration do
# hex-encoded # hex-encoded
field :apns_device_token, :string field :apns_device_token, :string
field :push_version, :integer
timestamps() timestamps()
end 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 def create_changeset(registration \\ %__MODULE__{}, params) do
registration registration

View File

@ -8,13 +8,15 @@ defmodule TuskerPushWeb.RegistrationsController do
def create(conn, %{ def create(conn, %{
"transaction_id" => transaction_id, "transaction_id" => transaction_id,
"environment" => env, "environment" => env,
"device_token" => token "device_token" => token,
"push_version" => version
}) do }) do
with {:ok, %Registration{id: id}} <- with {:ok, %Registration{id: id}} <-
TuskerPush.register(%{ TuskerPush.register(%{
storekit_original_transaction_id: transaction_id, storekit_original_transaction_id: transaction_id,
apns_environment: env, apns_environment: env,
apns_device_token: token apns_device_token: token,
push_version: version
}) do }) do
conn conn
|> json(%{ |> json(%{

View File

@ -10,6 +10,8 @@ defmodule TuskerPush.Repo.Migrations.CreateRegistrations do
add :apns_environment, :string, null: false add :apns_environment, :string, null: false
add :apns_device_token, :string, null: false add :apns_device_token, :string, null: false
add :push_version, :integer, null: false
timestamps() timestamps()
end end
end end