core: wait chat started in deleteTimedItem threads (#1626)

This commit is contained in:
JRoberts
2022-12-22 19:18:38 +04:00
committed by GitHub
parent aae0802ec8
commit 8dac96f415

View File

@@ -1739,8 +1739,7 @@ cleanupManager :: forall m. ChatMonad m => User -> m ()
cleanupManager user = do
forever $ do
flip catchError (toView . CRChatError) $ do
agentStarted <- asks agentAsync
atomically $ readTVar agentStarted >>= \a -> unless (isJust a) retry
waitChatStarted
cleanupTimedItems
threadDelay $ cleanupManagerInterval * 1000000
where
@@ -1775,6 +1774,7 @@ deleteTimedItem :: ChatMonad m => User -> (ChatRef, ChatItemId) -> UTCTime -> m
deleteTimedItem user (ChatRef cType chatId, itemId) deleteAt = do
ts <- liftIO getCurrentTime
threadDelay $ diffInMicros deleteAt ts
waitChatStarted
case cType of
CTDirect -> do
(ct, ci) <- withStore $ \db -> (,) <$> getContact db user chatId <*> getDirectChatItem db user chatId itemId
@@ -3589,6 +3589,11 @@ withUser action = withUser' $ \user ->
chatStarted :: ChatMonad m => m Bool
chatStarted = fmap isJust . readTVarIO =<< asks agentAsync
waitChatStarted :: ChatMonad m => m ()
waitChatStarted = do
agentStarted <- asks agentAsync
atomically $ readTVar agentStarted >>= \a -> unless (isJust a) retry
withAgent :: ChatMonad m => (AgentClient -> ExceptT AgentErrorType m a) -> m a
withAgent action =
asks smpAgent