From 855881094b33899cfc1c8ee66e0ddc8fac0f48a0 Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Tue, 8 Feb 2022 13:04:17 +0400 Subject: [PATCH] add CRContactConnecting api response (#281) --- src/Simplex/Chat.hs | 5 +++-- src/Simplex/Chat/Controller.hs | 1 + src/Simplex/Chat/Store.hs | 12 ++++++------ src/Simplex/Chat/View.hs | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index e859979816..47281fc066 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -964,8 +964,9 @@ processAgentMessage (Just user@User {userId, profile}) agentConnId agentMessage saveConnInfo activeConn connInfo = do ChatMessage {chatMsgEvent} <- liftEither $ parseChatMessage connInfo case chatMsgEvent of - XInfo p -> - withStore $ \st -> createDirectContact st userId activeConn p + XInfo p -> do + ct <- withStore $ \st -> createDirectContact st userId activeConn p + toView $ CRContactConnecting ct -- TODO show/log error, other events in SMP confirmation _ -> pure () diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index 5ac7092fcc..d6c6eb6f62 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -173,6 +173,7 @@ data ChatResponse | CRSndFileRcvCancelled {sndFileTransfer :: SndFileTransfer} | CRSndGroupFileCancelled {sndFileTransfers :: [SndFileTransfer]} | CRUserProfileUpdated {fromProfile :: Profile, toProfile :: Profile} + | CRContactConnecting {contact :: Contact} | CRContactConnected {contact :: Contact} | CRContactAnotherClient {contact :: Contact} | CRContactDisconnected {contact :: Contact} diff --git a/src/Simplex/Chat/Store.hs b/src/Simplex/Chat/Store.hs index 0a1e01b991..bac8603961 100644 --- a/src/Simplex/Chat/Store.hs +++ b/src/Simplex/Chat/Store.hs @@ -272,12 +272,12 @@ createConnection_ db userId connType entityId acId viaContact connLevel currentT where ent ct = if connType == ct then entityId else Nothing -createDirectContact :: StoreMonad m => SQLiteStore -> UserId -> Connection -> Profile -> m () -createDirectContact st userId Connection {connId} profile = - void $ - liftIOEither . withTransaction st $ \db -> do - currentTs <- getCurrentTime - createContact_ db userId connId profile Nothing currentTs +createDirectContact :: StoreMonad m => SQLiteStore -> UserId -> Connection -> Profile -> m Contact +createDirectContact st userId activeConn@Connection {connId} profile = + liftIOEither . withTransaction st $ \db -> runExceptT $ do + createdAt <- liftIO getCurrentTime + (localDisplayName, contactId, _) <- ExceptT $ createContact_ db userId connId profile Nothing createdAt + pure $ Contact {contactId, localDisplayName, profile, activeConn, viaGroup = Nothing, createdAt} createContact_ :: DB.Connection -> UserId -> Int64 -> Profile -> Maybe Int64 -> UTCTime -> IO (Either StoreError (Text, Int64, Int64)) createContact_ db userId connId Profile {displayName, fullName} viaGroup currentTs = diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 00141c345c..b798861716 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -89,6 +89,7 @@ responseToView cmd = \case CRSndFileCancelled ft -> sendingFile_ "cancelled" ft CRSndFileRcvCancelled ft@SndFileTransfer {recipientDisplayName = c} -> [ttyContact c <> " cancelled receiving " <> sndFile ft] + CRContactConnecting _ -> [] CRContactConnected ct -> [ttyFullContact ct <> ": contact is connected"] CRContactAnotherClient c -> [ttyContact' c <> ": contact is connected to another client"] CRContactDisconnected c -> [ttyContact' c <> ": disconnected from server (messages will be queued)"]