From 9f6316fa6dbdf8b23aa026deb750b64ba9b332a5 Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Mon, 30 May 2022 22:58:47 +0400 Subject: [PATCH] fix getDeviceNtfToken (#376) --- src/Simplex/Messaging/Agent/Store/SQLite.hs | 8 ++++---- .../Store/SQLite/Migrations/M20220322_notifications.hs | 2 +- .../Agent/Store/SQLite/Migrations/agent_schema.sql | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index 0400ef07e..5c4e679b7 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -45,7 +45,7 @@ import Data.Text (Text) import qualified Data.Text as T import Data.Text.Encoding (decodeLatin1) import Data.Time.Clock (getCurrentTime) -import Database.SQLite.Simple (FromRow, NamedParam (..), Only (..), SQLError, ToRow, field) +import Database.SQLite.Simple (FromRow, NamedParam (..), Only (..), SQLError, ToRow, field, (:.) (..)) import qualified Database.SQLite.Simple as DB import Database.SQLite.Simple.FromField import Database.SQLite.Simple.QQ (sql) @@ -587,16 +587,16 @@ instance (MonadUnliftIO m, MonadError StoreError m) => MonadAgentStore SQLiteSto db [sql| SELECT s.ntf_host, s.ntf_port, s.ntf_key_hash, - t.tkn_id, t.tkn_pub_key, t.tkn_priv_key, t.tkn_pub_dh_key, t.tkn_priv_dh_key, t.tkn_dh_secret, t.tkn_status, t.tkn_action + t.provider, t.device_token, t.tkn_id, t.tkn_pub_key, t.tkn_priv_key, t.tkn_pub_dh_key, t.tkn_priv_dh_key, t.tkn_dh_secret, t.tkn_status, t.tkn_action FROM ntf_tokens t JOIN ntf_servers s USING (ntf_host, ntf_port) |] pure . first listToMaybe $ partition ((t ==) . deviceToken) tokens where - ntfToken (host, port, keyHash, ntfTokenId, ntfPubKey, ntfPrivKey, ntfDhPubKey, ntfDhPrivKey, ntfDhSecret, ntfTknStatus, ntfTknAction) = + ntfToken ((host, port, keyHash) :. (provider, dt, ntfTokenId, ntfPubKey, ntfPrivKey, ntfDhPubKey, ntfDhPrivKey, ntfDhSecret, ntfTknStatus, ntfTknAction)) = let ntfServer = ProtocolServer {host, port, keyHash} ntfDhKeys = (ntfDhPubKey, ntfDhPrivKey) - in NtfToken {deviceToken = t, ntfServer, ntfTokenId, ntfPubKey, ntfPrivKey, ntfDhKeys, ntfDhSecret, ntfTknStatus, ntfTknAction} + in NtfToken {deviceToken = DeviceToken provider dt, ntfServer, ntfTokenId, ntfPubKey, ntfPrivKey, ntfDhKeys, ntfDhSecret, ntfTknStatus, ntfTknAction} updateNtfTokenRegistration :: SQLiteStore -> NtfToken -> NtfTokenId -> C.DhSecretX25519 -> m () updateNtfTokenRegistration st NtfToken {deviceToken = DeviceToken provider token, ntfServer = ProtocolServer {host, port}} tknId ntfDhSecret = diff --git a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20220322_notifications.hs b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20220322_notifications.hs index 4b93c0db9..4ee6695d4 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20220322_notifications.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20220322_notifications.hs @@ -19,7 +19,7 @@ CREATE TABLE ntf_servers ( CREATE TABLE ntf_tokens ( provider TEXT NOT NULL, -- apn - device_token TEXT NOT NULL, + device_token TEXT NOT NULL, -- ! this field is mislabeled and is actually saved as binary ntf_host TEXT NOT NULL, ntf_port TEXT NOT NULL, tkn_id BLOB, -- token ID assigned by notifications server diff --git a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/agent_schema.sql b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/agent_schema.sql index 4fd602e87..d5fbc7718 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/agent_schema.sql +++ b/src/Simplex/Messaging/Agent/Store/SQLite/Migrations/agent_schema.sql @@ -142,7 +142,7 @@ CREATE TABLE ntf_servers( ) WITHOUT ROWID; CREATE TABLE ntf_tokens( provider TEXT NOT NULL, -- apn - device_token TEXT NOT NULL, + device_token TEXT NOT NULL, -- ! this field is mislabeled and is actually saved as binary ntf_host TEXT NOT NULL, ntf_port TEXT NOT NULL, tkn_id BLOB, -- token ID assigned by notifications server