summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-07-17 22:29:22 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-07-26 21:55:07 +0200
commit97427b2f49daa9d86661ad999d4da17ac7a4acb4 (patch)
tree9e8b064932c844a4cbd44a191f74f53776889cfc /src/Main.hs
parent479b63d8c30c0bc6e6475882d7fb573db5dad1f9 (diff)
Contacts using Set sructure
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs
index d764fe0..295a486 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -15,6 +15,7 @@ import qualified Data.ByteString.Lazy as BL
import Data.Char
import Data.List
import Data.Maybe
+import Data.Ord
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Time.LocalTime
@@ -35,6 +36,7 @@ import Message
import Network
import PubKey
import Service
+import Set
import State
import Storage
import Storage.Merge
@@ -313,11 +315,14 @@ cmdContacts :: Command
cmdContacts = do
args <- words <$> asks ciLine
ehead <- asks ciHead
- let contacts = toContactList $ lookupSharedValue $ lsShared $ headObject ehead
+ let contacts = fromSetBy (comparing contactName) $ lookupSharedValue $ lsShared $ headObject ehead
verbose = "-v" `elem` args
forM_ (zip [1..] contacts) $ \(i :: Int, c) -> do
- liftIO $ putStrLn $ show i ++ ": " ++ T.unpack (displayIdentity $ contactIdentity c) ++
- (if verbose then " " ++ (unwords $ map (BC.unpack . showRef . storedRef) $ idDataF $ contactIdentity c) else "")
+ liftIO $ putStrLn $ concat
+ [ show i, ": ", T.unpack $ contactName c
+ , case contactIdentity c of Nothing -> ""; Just idt -> " (" ++ T.unpack (displayIdentity idt) ++ ")"
+ , if verbose then " " ++ (unwords $ map (BC.unpack . showRef . storedRef) $ maybe [] idDataF $ contactIdentity c) else ""
+ ]
cmdContactAdd :: Command
cmdContactAdd = join $ contactRequest