From 79a1c1db2e7c29b612ba67a303a89a10be4a7e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 2 Aug 2025 18:57:56 +0200 Subject: Watch direct messages using local state diffs Changelog: API: Replaced `watchReceivedDirectMessages` with `watchDirectMessageThreads` --- main/Main.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'main/Main.hs') diff --git a/main/Main.hs b/main/Main.hs index 974038f..d95e766 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -369,16 +369,20 @@ interactiveLoop st opts = withTerminal commandCompletion $ \term -> do _ <- liftIO $ do tzone <- getCurrentTimeZone - watchReceivedDirectMessages erebosHead $ \smsg -> do - let msg = fromStored smsg - extPrintLn $ formatDirectMessage tzone msg - case optDmBotEcho opts of - Nothing -> return () - Just prefix -> do - res <- runExceptT $ flip runReaderT erebosHead $ sendDirectMessage (msgFrom msg) (prefix <> msgText msg) - case res of - Right reply -> extPrintLn $ formatDirectMessage tzone $ fromStored reply - Left err -> extPrintLn $ "Failed to send dm echo: " <> err + let self = finalOwner $ headLocalIdentity erebosHead + watchDirectMessageThreads erebosHead $ \prev cur -> do + forM_ (reverse $ dmThreadToListSince prev cur) $ \msg -> do + extPrintLn $ formatDirectMessage tzone msg + case optDmBotEcho opts of + Just prefix + | not (msgFrom msg `sameIdentity` self) + -> do + void $ forkIO $ do + res <- runExceptT $ flip runReaderT erebosHead $ sendDirectMessage (msgFrom msg) (prefix <> msgText msg) + case res of + Right _ -> return () + Left err -> extPrintLn $ "Failed to send dm echo: " <> err + _ -> return () peers <- liftIO $ newMVar [] contextOptions <- liftIO $ newMVar [] @@ -682,11 +686,7 @@ cmdSend :: Command cmdSend = void $ do text <- asks ciLine conv <- getSelectedConversation - sendMessage conv (T.pack text) >>= \case - Just msg -> do - tzone <- liftIO $ getCurrentTimeZone - cmdPutStrLn $ formatMessage tzone msg - Nothing -> return () + void $ sendMessage conv (T.pack text) cmdDelete :: Command cmdDelete = void $ do -- cgit v1.2.3