core: process ERR response to async command (#1061)

This commit is contained in:
JRoberts authored and GitHub committed 2022-09-16 19:30:02 +04:00
1 parent d5b9f4014e
commit e8c14896aa
5 files changed
+39 -13

No files matched your search

@@ -9,7 +9,7 @@ m20220909_commands :: Query
m20220909_commands =
[sql|
CREATE TABLE commands (
command_id INTEGER PRIMARY KEY, -- used as ACorrId
command_id INTEGER PRIMARY KEY AUTOINCREMENT, -- used as ACorrId
connection_id INTEGER REFERENCES connections ON DELETE CASCADE,
command_function TEXT NOT NULL,
command_status TEXT NOT NULL,
+2 -1
View File
@@ -403,7 +403,7 @@ CREATE INDEX idx_chat_items_contacts ON chat_items(
chat_item_id
);
CREATE TABLE commands(
command_id INTEGER PRIMARY KEY, -- used as ACorrId
command_id INTEGER PRIMARY KEY AUTOINCREMENT, -- used as ACorrId
connection_id INTEGER REFERENCES connections ON DELETE CASCADE,
command_function TEXT NOT NULL,
command_status TEXT NOT NULL,
@@ -411,3 +411,4 @@ CREATE TABLE commands(
created_at TEXT NOT NULL DEFAULT(datetime('now')),
updated_at TEXT NOT NULL DEFAULT(datetime('now'))
);
CREATE TABLE sqlite_sequence(name,seq);
+5
View File
@@ -179,6 +179,7 @@ module Simplex.Chat.Store
getCalls,
createCommand,
setCommandConnId,
deleteCommand,
updateCommandStatus,
getCommandDataByCorrId,
setConnConnReqInv,
@@ -3919,6 +3920,10 @@ setCommandConnId db User {userId} cmdId connId = do
|]
(connId, updatedAt, userId, cmdId)
deleteCommand :: DB.Connection -> User -> CommandId -> IO ()
deleteCommand db User {userId} cmdId =
DB.execute db "DELETE FROM commands WHERE user_id = ? AND command_id = ?" (userId, cmdId)
updateCommandStatus :: DB.Connection -> User -> CommandId -> CommandStatus -> IO ()
updateCommandStatus db User {userId} cmdId status = do
updatedAt <- getCurrentTime
+4 -1
View File
@@ -926,7 +926,8 @@ commandId = unpack
data CommandStatus
= CSCreated
| CSCompleted
| CSCompleted -- unused - was replaced with deleteCommand
| CSError -- internal command error, e.g. not matching connection id or unexpected response, not related to agent message ERR
deriving (Show, Generic)
instance FromField CommandStatus where fromField = fromTextField_ textDecode
@@ -937,10 +938,12 @@ instance TextEncoding CommandStatus where
textDecode = \case
"created" -> Just CSCreated
"completed" -> Just CSCompleted
"error" -> Just CSError
_ -> Nothing
textEncode = \case
CSCreated -> "created"
CSCompleted -> "completed"
CSError -> "error"
data CommandFunction
= CFCreateConn