summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-05-22 21:46:03 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-05-23 21:10:12 +0200
commit03bcd5ae6518f6d672fec1bdd109184624aa6608 (patch)
tree348d795e91c494ecbade7d7973ae56f76ecf1eb5
parent620e5840aba91d683bf7b4ee115079550aae8569 (diff)
Details command
Changelog: Added `/details` command for info about selected conversation
-rw-r--r--README.md3
-rw-r--r--main/Main.hs61
2 files changed, 64 insertions, 0 deletions
diff --git a/README.md b/README.md
index 66e471c..4ee75f7 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,9 @@ Send `<message>` to selected conversation.
`/history`
Show message history of the selected conversation.
+`/details`
+Show information about the selected conversations, contact or peer.
+
### Add contacts
To ensure the identity of the contact and prevent man-in-the-middle attack,
diff --git a/main/Main.hs b/main/Main.hs
index 22a7831..0857191 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -382,6 +382,7 @@ commands =
, ("contact-accept", cmdContactAccept)
, ("contact-reject", cmdContactReject)
, ("conversations", cmdConversations)
+ , ("details", cmdDetails)
#ifdef ENABLE_ICE_SUPPORT
, ("discovery-init", cmdDiscoveryInit)
, ("discovery", cmdDiscovery)
@@ -503,6 +504,66 @@ cmdConversations = do
forM_ (zip [1..] conversations) $ \(i :: Int, conv) -> do
liftIO $ putStrLn $ "[" ++ show i ++ "] " ++ T.unpack (conversationName conv)
+cmdDetails :: Command
+cmdDetails = do
+ gets csContext >>= \case
+ SelectedPeer peer -> do
+ liftIO $ putStr $ unlines
+ [ "Network peer:"
+ , " " <> show (peerAddress peer)
+ ]
+ peerIdentity peer >>= \case
+ PeerIdentityUnknown _ -> liftIO $ do
+ putStrLn $ "unknown identity"
+ PeerIdentityRef wref _ -> liftIO $ do
+ putStrLn $ "Identity ref:"
+ putStrLn $ " " <> BC.unpack (showRefDigest $ wrDigest wref)
+ PeerIdentityFull pid -> printContactOrIdentityDetails pid
+
+ SelectedContact contact -> do
+ printContactDetails contact
+
+ SelectedConversation conv -> do
+ case conversationPeer conv of
+ Just pid -> printContactOrIdentityDetails pid
+ Nothing -> liftIO $ putStrLn $ "(conversation without peer)"
+
+ NoContext -> liftIO $ putStrLn "nothing selected"
+ where
+ printContactOrIdentityDetails cid = do
+ contacts <- fromSetBy (comparing contactName) . lookupSharedValue . lsShared . fromStored <$> getLocalHead
+ case find (maybe False (sameIdentity cid) . contactIdentity) contacts of
+ Just contact -> printContactDetails contact
+ Nothing -> printIdentityDetails cid
+
+ printContactDetails contact = liftIO $ do
+ putStrLn $ "Contact:"
+ prefix <- case contactCustomName contact of
+ Just name -> do
+ putStrLn $ " " <> T.unpack name
+ return $ Just "alias of"
+ Nothing -> do
+ return $ Nothing
+
+ case contactIdentity contact of
+ Just cid -> do
+ printIdentityDetailsBody prefix cid
+ Nothing -> do
+ putStrLn $ " (without erebos identity)"
+
+ printIdentityDetails identity = liftIO $ do
+ putStrLn $ "Identity:"
+ printIdentityDetailsBody Nothing identity
+
+ printIdentityDetailsBody prefix identity = do
+ forM_ (zip (False : repeat True) $ unfoldOwners identity) $ \(owned, cpid) -> do
+ putStrLn $ unwords $ concat
+ [ [ " " ]
+ , if owned then [ "owned by" ] else maybeToList prefix
+ , [ maybe "<unnamed>" T.unpack (idName cpid) ]
+ , map (BC.unpack . showRefDigest . refDigest . storedRef) $ idExtDataF cpid
+ ]
+
#ifdef ENABLE_ICE_SUPPORT
cmdDiscoveryInit :: Command