summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-05-18 09:11:35 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-05-18 09:11:35 +0200
commitd17d4f238afbd04f61545d49bfccc108421e9261 (patch)
tree8927d2a4aa415f18408405cbfe1ae8366897f25e
parent071ed5842de1764d3bdf086677079090df5e272f (diff)
parent51cfc27698b8e59b08df2d71da3f3ba89ed55b96 (diff)
Merge branch 'release-0.1'HEADmaster
-rw-r--r--README.md23
-rw-r--r--main/Main.hs39
2 files changed, 39 insertions, 23 deletions
diff --git a/README.md b/README.md
index 07cee2a..8957dd7 100644
--- a/README.md
+++ b/README.md
@@ -102,11 +102,13 @@ Test chatroom [19:03] Some Name: Hi
`<message>`
: Send `<message>` to selected conversation.
-`/history`
-: Show message history of the selected conversation.
+`/history [<number>]`
+: Show message history of the selected conversation, or the one identified by
+ `<number>` if given.
-`/details`
-: Show information about the selected conversations, contact or peer.
+`/details [<number>]`
+: Show information about the selected conversations, contact or peer; or the
+ one identified by `<number>` if given.
### Chatrooms
@@ -137,12 +139,13 @@ are signed, so message author can not be forged.
: Leave the chatroom. User will no longer be listed as a member and erebos tool
will no longer collect message of this chatroom.
-`/delete`
-: Delete the chatroom; this action is only synchronized with devices belonging
-to the current user and does not affect the chatroom state for others. Due to
-the storage design, the chatroom data will not be purged from the local state
-history, but the chatroom will no longer be listed as available and no futher
-updates for this chatroom will be collected or shared with other peers.
+`/delete [<number>]`
+: Delete the chatroom (currently selected one, or the one identified by
+ `<number>`); this action is only synchronized with devices belonging to the
+ current user and does not affect the chatroom state for others. Due to the
+ storage design, the chatroom data will not be purged from the local state
+ history, but the chatroom will no longer be listed as available and no futher
+ updates for this chatroom will be collected or shared with other peers.
### Add contacts
diff --git a/main/Main.hs b/main/Main.hs
index a1a8b50..a0c28f7 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -503,7 +503,10 @@ getSelectedChatroom = gets csContext >>= \case
_ -> throwOtherError "no chatroom selected"
getSelectedConversation :: CommandM Conversation
-getSelectedConversation = gets csContext >>= \case
+getSelectedConversation = gets csContext >>= getConversationFromContext
+
+getConversationFromContext :: CommandContext -> CommandM Conversation
+getConversationFromContext = \case
SelectedPeer peer -> peerIdentity peer >>= \case
PeerIdentityFull pid -> directMessageConversation $ finalOwner pid
_ -> throwOtherError "incomplete peer identity"
@@ -517,6 +520,13 @@ getSelectedConversation = gets csContext >>= \case
SelectedConversation conv -> reloadConversation conv
_ -> throwOtherError "no contact, peer or conversation selected"
+getSelectedOrManualContext :: CommandM CommandContext
+getSelectedOrManualContext = do
+ asks ciLine >>= \case
+ "" -> gets csContext
+ str | all isDigit str -> getContextByIndex (read str)
+ _ -> throwOtherError "invalid index"
+
commands :: [(String, Command)]
commands =
[ ("history", cmdHistory)
@@ -638,19 +648,22 @@ cmdMembers = do
forM_ (chatroomMembers room) $ \x -> do
cmdPutStrLn $ maybe "<unnamed>" T.unpack $ idName x
+getContextByIndex :: Int -> CommandM CommandContext
+getContextByIndex n = do
+ join (asks ciContextOptions) >>= \ctxs -> if
+ | n > 0, (ctx : _) <- drop (n - 1) ctxs -> return ctx
+ | otherwise -> throwOtherError "invalid index"
cmdSelectContext :: Command
cmdSelectContext = do
n <- read <$> asks ciLine
- join (asks ciContextOptions) >>= \ctxs -> if
- | n > 0, (ctx : _) <- drop (n - 1) ctxs -> do
- modify $ \s -> s { csContext = ctx }
- case ctx of
- SelectedChatroom rstate -> do
- when (not (roomStateSubscribe rstate)) $ do
- chatroomSetSubscribe (head $ roomStateData rstate) True
- _ -> return ()
- | otherwise -> throwOtherError "invalid index"
+ ctx <- getContextByIndex n
+ modify $ \s -> s { csContext = ctx }
+ case ctx of
+ SelectedChatroom rstate -> do
+ when (not (roomStateSubscribe rstate)) $ do
+ chatroomSetSubscribe (head $ roomStateData rstate) True
+ _ -> return ()
cmdSend :: Command
cmdSend = void $ do
@@ -664,12 +677,12 @@ cmdSend = void $ do
cmdDelete :: Command
cmdDelete = void $ do
- deleteConversation =<< getSelectedConversation
+ deleteConversation =<< getConversationFromContext =<< getSelectedOrManualContext
modify $ \s -> s { csContext = NoContext }
cmdHistory :: Command
cmdHistory = void $ do
- conv <- getSelectedConversation
+ conv <- getConversationFromContext =<< getSelectedOrManualContext
case conversationHistory conv of
thread@(_:_) -> do
tzone <- liftIO $ getCurrentTimeZone
@@ -834,7 +847,7 @@ cmdConversations = do
cmdDetails :: Command
cmdDetails = do
- gets csContext >>= \case
+ getSelectedOrManualContext >>= \case
SelectedPeer peer -> do
cmdPutStrLn $ unlines
[ "Network peer:"