use sync commands (#306)

This commit is contained in:
Evgeny Poberezkin
2022-02-14 19:36:15 +00:00
committed by GitHub
parent c580c34a35
commit c37f41c171
3 changed files with 14 additions and 13 deletions

View File

@@ -382,17 +382,17 @@ processChatCommand = \case
withAgentLock a . withLock l $ action
-- below code would make command responses asynchronous where they can be slow
-- in View.hs `r'` should be defined as `id` in this case
procCmd :: m ChatResponse -> m ChatResponse
procCmd action = do
ChatController {chatLock = l, smpAgent = a, outputQ = q, idsDrg = gVar} <- ask
corrId <- liftIO $ SMP.CorrId <$> randomBytes gVar 8
void . forkIO $
withAgentLock a . withLock l $
(atomically . writeTBQueue q) . (Just corrId,) =<< (action `catchError` (pure . CRChatError))
pure $ CRCmdAccepted corrId
-- use function below to make commands "synchronous"
-- procCmd :: m ChatResponse -> m ChatResponse
-- procCmd = id
-- procCmd action = do
-- ChatController {chatLock = l, smpAgent = a, outputQ = q, idsDrg = gVar} <- ask
-- corrId <- liftIO $ SMP.CorrId <$> randomBytes gVar 8
-- void . forkIO $
-- withAgentLock a . withLock l $
-- (atomically . writeTBQueue q) . (Just corrId,) =<< (action `catchError` (pure . CRChatError))
-- pure $ CRCmdAccepted corrId
-- use function below to make commands "synchronous"
procCmd :: m ChatResponse -> m ChatResponse
procCmd = id
connectViaContact :: UserId -> ConnectionRequestUri 'CMContact -> Profile -> m ChatResponse
connectViaContact userId cReq profile = withChatLock $ do
let cReqHash = ConnReqUriHash . C.sha256Hash $ strEncode cReq

View File

@@ -67,7 +67,7 @@ responseToView cmd testView = \case
CRSentConfirmation -> r' ["confirmation sent!"]
CRSentInvitation -> r' ["connection request sent!"]
CRContactDeleted c -> r' [ttyContact' c <> ": contact is deleted"]
CRAcceptingContactRequest c -> r' [ttyFullContact c <> ": accepting contact request..."]
CRAcceptingContactRequest c -> r [ttyFullContact c <> ": accepting contact request..."]
CRContactAlreadyExists c -> r [ttyFullContact c <> ": contact already exists"]
CRContactRequestAlreadyAccepted c -> r' [ttyFullContact c <> ": sent you a duplicate contact request, but you are already connected, no action needed"]
CRUserContactLinkCreated cReq -> r' $ connReqContact_ "Your new chat address is created!" cReq
@@ -125,8 +125,8 @@ responseToView cmd testView = \case
where
r = (plain cmd :)
-- this function should be `r` for "synchronous", `id` for "asynchronous" command responses
-- r' = r
r' = id
r' = r
-- r' = id
testViewChats :: [AChat] -> [StyledString]
testViewChats chats = [sShow $ map toChatView chats]
where

View File

@@ -744,6 +744,7 @@ testUserContactLinkAutoAccept =
cath ##> ("/c " <> cLink)
cath <## "connection request sent!"
alice <## ""
alice <## "cath (Catherine): accepting contact request..."
concurrently_
(cath <## "alice (Alice): contact is connected")