summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-07-05 22:11:47 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-07-06 12:18:50 +0200
commit0a8b9157d4204115530f2981ff188d532c8426a5 (patch)
treec6d90a964a8dcde22321212f49dd5fe94f3fb085 /main
parentbd351e8d555001647e8501ac2d38c675a2a3c005 (diff)
Commands to list and create chatrooms
Diffstat (limited to 'main')
-rw-r--r--main/Main.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/main/Main.hs b/main/Main.hs
index 0eb414c..091f076 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -37,6 +37,7 @@ import System.IO
import Erebos.Attach
import Erebos.Contact
+import Erebos.Chatroom
import Erebos.Conversation
#ifdef ENABLE_ICE_SUPPORT
import Erebos.Discovery
@@ -425,6 +426,8 @@ commands =
, ("attach", cmdAttach)
, ("attach-accept", cmdAttachAccept)
, ("attach-reject", cmdAttachReject)
+ , ("chatrooms", cmdChatrooms)
+ , ("chatroom-create-public", cmdChatroomCreatePublic)
, ("contacts", cmdContacts)
, ("contact-add", cmdContactAdd)
, ("contact-accept", cmdContactAccept)
@@ -530,6 +533,30 @@ cmdAttachAccept = attachAccept =<< getSelectedPeer
cmdAttachReject :: Command
cmdAttachReject = attachReject =<< getSelectedPeer
+cmdChatrooms :: Command
+cmdChatrooms = do
+ chatrooms <- listChatrooms
+ forM_ chatrooms $ \case
+ rstate | Just room <- roomStateRoom rstate -> do
+ liftIO $ T.putStrLn $ T.concat
+ [ fromMaybe (T.pack "<unnamed>") $ roomName room
+ ]
+ _ -> return ()
+
+cmdChatroomCreatePublic :: Command
+cmdChatroomCreatePublic = do
+ name <- asks ciLine >>= \case
+ line | not (null line) -> return $ T.pack line
+ _ -> liftIO $ do
+ T.putStr $ T.pack "Name: "
+ hFlush stdout
+ T.getLine
+
+ void $ createChatroom
+ (if T.null name then Nothing else Just name)
+ Nothing
+
+
cmdContacts :: Command
cmdContacts = do
args <- words <$> asks ciLine