diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 2f4e5f3edd..84989d9573 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -23,8 +23,8 @@ import Data.Attoparsec.ByteString.Char8 (Parser) import qualified Data.Attoparsec.ByteString.Char8 as A import Data.Bifunctor (first) import Data.ByteString.Char8 (ByteString) -import Data.Char (isSpace) import qualified Data.ByteString.Char8 as B +import Data.Char (isSpace) import Data.Functor (($>)) import Data.Int (Int64) import Data.List (find) @@ -191,12 +191,8 @@ processChatCommand user@User {userId, profile} = \case (connId, cReq) <- withAgent (`createConnection` SCMInvitation) withStore $ \st -> createDirectConnection st userId connId showInvitation cReq - Connect (ACR cMode cReq) -> do - let msg :: ChatMsgEvent = case cMode of - SCMInvitation -> XInfo profile - SCMContact -> XContact profile Nothing - connId <- withAgent $ \a -> joinConnection a cReq $ directMessage msg - withStore $ \st -> createDirectConnection st userId connId + Connect (ACR SCMInvitation cReq) -> connect cReq (XInfo profile) >> showSentConfirmation + Connect (ACR SCMContact cReq) -> connect cReq (XContact profile Nothing) >> showSentInvitation DeleteContact cName -> withStore (\st -> getContactGroupNames st userId cName) >>= \case [] -> do @@ -360,6 +356,10 @@ processChatCommand user@User {userId, profile} = \case QuitChat -> liftIO exitSuccess ShowVersion -> printToView clientVersionInfo where + connect :: ConnectionRequest c -> ChatMsgEvent -> m () + connect cReq msg = do + connId <- withAgent $ \a -> joinConnection a cReq $ directMessage msg + withStore $ \st -> createDirectConnection st userId connId contactMember :: Contact -> [GroupMember] -> Maybe GroupMember contactMember Contact {contactId} = find $ \GroupMember {memberContactId = cId, memberStatus = s} -> diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 55c3afa017..44e8bc9a9e 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -8,6 +8,8 @@ module Simplex.Chat.View ( printToView, showInvitation, + showSentConfirmation, + showSentInvitation, showChatError, showContactDeleted, showContactGroups, @@ -82,7 +84,7 @@ import Data.ByteString.Char8 (ByteString) import Data.Composition ((.:), (.:.)) import Data.Function (on) import Data.Int (Int64) -import Data.List (groupBy, intersperse, sortOn, sort) +import Data.List (groupBy, intersperse, sort, sortOn) import Data.Text (Text) import qualified Data.Text as T import Data.Time.Clock (DiffTime, UTCTime) @@ -105,6 +107,12 @@ type ChatReader m = (MonadUnliftIO m, MonadReader ChatController m) showInvitation :: ChatReader m => ConnReqInvitation -> m () showInvitation = printToView . connReqInvitation_ +showSentConfirmation :: ChatReader m => m () +showSentConfirmation = printToView ["confirmation sent!"] + +showSentInvitation :: ChatReader m => m () +showSentInvitation = printToView ["connection request sent!"] + showChatError :: ChatReader m => ChatError -> m () showChatError = printToView . chatError diff --git a/tests/ChatTests.hs b/tests/ChatTests.hs index e83d9d24ef..05cc7a2bf7 100644 --- a/tests/ChatTests.hs +++ b/tests/ChatTests.hs @@ -58,6 +58,7 @@ testAddContact = alice ##> "/c" inv <- getInvitation alice bob ##> ("/c " <> inv) + bob <## "confirmation sent!" concurrently_ (bob <## "alice (Alice): contact is connected") (alice <## "bob (Bob): contact is connected") @@ -69,6 +70,7 @@ testAddContact = alice ##> "/c" inv' <- getInvitation alice bob ##> ("/c " <> inv') + bob <## "confirmation sent!" concurrently_ (bob <## "alice_1 (Alice): contact is connected") (alice <## "bob_1 (Bob): contact is connected") @@ -641,6 +643,7 @@ connectUsers cc1 cc2 = do cc1 ##> "/c" inv <- getInvitation cc1 cc2 ##> ("/c " <> inv) + cc2 <## "confirmation sent!" concurrently_ (cc2 <## (name1 <> ": contact is connected")) (cc1 <## (name2 <> ": contact is connected")) @@ -737,6 +740,7 @@ cc <# line = (dropTime <$> getTermLine cc) `shouldReturn` line cc1 <#? cc2 = do name <- userName cc2 sName <- showName cc2 + cc2 <## "connection request sent!" cc1 <## (sName <> " wants to connect to you!") cc1 <## ("to accept: /ac " <> name) cc1 <## ("to reject: /rc " <> name <> " (the sender will NOT be notified)")