summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-04-13 08:29:25 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-04-17 20:59:41 +0200
commit2c297cb6747080cd47cdcd9bbd23c5f24a092e8f (patch)
tree17dc2a42dc3d33ac92e5dfcd95c442626c11597a /main
parent943cd6e754453f70deae6ad89c6045b42c59e9c9 (diff)
Chatroom metadata updates
Diffstat (limited to 'main')
-rw-r--r--main/Test.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/main/Test.hs b/main/Test.hs
index b32872a..7aadd47 100644
--- a/main/Test.hs
+++ b/main/Test.hs
@@ -268,6 +268,7 @@ commands = map (T.pack *** id)
, ("chatroom-create", cmdChatroomCreate)
, ("chatroom-list-local", cmdChatroomListLocal)
, ("chatroom-watch-local", cmdChatroomWatchLocal)
+ , ("chatroom-set-name", cmdChatroomSetName)
]
cmdStore :: Command
@@ -574,7 +575,22 @@ cmdDmListContact = do
cmdChatroomCreate :: Command
cmdChatroomCreate = do
[name] <- asks tiParams
- void $ createChatroom (Just name) Nothing
+ room <- createChatroom (Just name) Nothing
+ cmdOut $ unwords $ "chatroom-create-done" : chatroomInfo room
+
+getChatroomStateData :: Text -> CommandM (Stored ChatroomStateData)
+getChatroomStateData tref = do
+ st <- asks tiStorage
+ Just ref <- liftIO $ readRef st (encodeUtf8 tref)
+ return $ wrappedLoad ref
+
+cmdChatroomSetName :: Command
+cmdChatroomSetName = do
+ [cid, name] <- asks tiParams
+ sdata <- getChatroomStateData cid
+ updateChatroomByStateData sdata (Just name) Nothing >>= \case
+ Just room -> cmdOut $ unwords $ "chatroom-set-name-done" : chatroomInfo room
+ Nothing -> cmdOut "chatroom-set-name-failed"
cmdChatroomListLocal :: Command
cmdChatroomListLocal = do
@@ -594,9 +610,11 @@ cmdChatroomWatchLocal = do
Just diff -> forM_ diff $ \case
AddedChatroom room -> outLine out $ unwords $ "chatroom-watched-added" : chatroomInfo room
RemovedChatroom room -> outLine out $ unwords $ "chatroom-watched-removed" : chatroomInfo room
- UpdatedChatroom oldroom room -> outLine out $ unwords $ "chatroom-watched-updated" : chatroomInfo room ++
- map (show . refDigest . storedRef) (roomStateData oldroom) ++
- map (show . refDigest . storedRef) (roomStateData room)
+ UpdatedChatroom oldroom room -> outLine out $ unwords $ concat
+ [ [ "chatroom-watched-updated" ], chatroomInfo room
+ , [ "old" ], map (show . refDigest . storedRef) (roomStateData oldroom)
+ , [ "new" ], map (show . refDigest . storedRef) (roomStateData room)
+ ]
chatroomInfo :: ChatroomState -> [String]
chatroomInfo room =