From 214aa9142556cbee2cea214d395a7cf9a2c86c4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roman=20Smr=C5=BE?= <roman.smrz@seznam.cz>
Date: Tue, 9 Feb 2021 21:32:28 +0100
Subject: Properly handle empty history listing

---
 src/Main.hs | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/Main.hs b/src/Main.hs
index 6fc27b7..4bb2f14 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -258,10 +258,13 @@ cmdHistory = void $ do
     PeerIdentityFull pid <- peerIdentity peer
     let powner = finalOwner pid
 
-    Just thread <- return $ find (sameIdentity powner . msgPeer) $
-        messageThreadView $ lookupSharedValue $ lsShared $ headObject ehead
-    tzone <- liftIO $ getCurrentTimeZone
-    liftIO $ mapM_ (putStrLn . formatMessage tzone) $ reverse $ take 50 $ threadToList thread
+    case find (sameIdentity powner . msgPeer) $
+            messageThreadView $ lookupSharedValue $ lsShared $ headObject ehead of
+        Just thread -> do
+            tzone <- liftIO $ getCurrentTimeZone
+            liftIO $ mapM_ (putStrLn . formatMessage tzone) $ reverse $ take 50 $ threadToList thread
+        Nothing -> do
+            liftIO $ putStrLn $ "<empty history>"
 
 cmdUpdateIdentity :: Command
 cmdUpdateIdentity = void $ do
-- 
cgit v1.2.3