summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-08-09 22:26:47 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2020-08-10 21:19:36 +0200
commit08ddfb1c4efe532ba10fdf594626a3ad794bb65e (patch)
treeff28fd173d7b9f5b234744f8d317a1b68b024c7f /src/Main.hs
parent3caea2bfbbddf2b3d872eb16e15877194bdfe0d6 (diff)
Contact: shared state and service
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs
index c961f4f..96186a8 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -25,6 +25,7 @@ import System.Console.Haskeline
import System.Environment
import Attach
+import Contact
import Identity
import Message
import Network
@@ -100,6 +101,7 @@ interactiveLoop st bhost = runInputT defaultSettings $ do
startServer erebosHead extPrintLn bhost
[ SomeService @AttachService Proxy
, SomeService @SyncService Proxy
+ , SomeService @ContactService Proxy
, SomeService @DirectMessage Proxy
]
@@ -190,6 +192,9 @@ commands =
, ("update-identity", cmdUpdateIdentity)
, ("attach", cmdAttach)
, ("attach-accept", cmdAttachAccept)
+ , ("contacts", cmdContacts)
+ , ("contact-add", cmdContactAdd)
+ , ("contact-accept", cmdContactAccept)
]
cmdUnknown :: String -> Command
@@ -252,3 +257,22 @@ cmdAttachAccept = join $ attachAccept
<$> asks ciPrint
<*> asks ciHead
<*> (maybe (throwError "no peer selected") return =<< gets csPeer)
+
+cmdContacts :: Command
+cmdContacts = do
+ ehead <- asks ciHead
+ let contacts = contactView $ lookupSharedValue $ lsShared $ headObject ehead
+ forM_ (zip [1..] contacts) $ \(i :: Int, c) -> do
+ liftIO $ putStrLn $ show i ++ ": " ++ T.unpack (displayIdentity $ contactIdentity c)
+
+cmdContactAdd :: Command
+cmdContactAdd = join $ contactRequest
+ <$> asks ciPrint
+ <*> asks (headLocalIdentity . ciHead)
+ <*> (maybe (throwError "no peer selected") return =<< gets csPeer)
+
+cmdContactAccept :: Command
+cmdContactAccept = join $ contactAccept
+ <$> asks ciPrint
+ <*> asks ciHead
+ <*> (maybe (throwError "no peer selected") return =<< gets csPeer)