From 4bbdcc1d06c9c4ffd8098c92450d05f0ee923314 Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Sun, 5 Sep 2021 05:38:11 +1000 Subject: [PATCH] update help - file transfer and groups (#98) * update help - file transfer and groups * update help * update help * update help Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- src/Simplex/Chat.hs | 16 ++++-- src/Simplex/Chat/Help.hs | 105 +++++++++++++++++++++++++++++---------- 2 files changed, 91 insertions(+), 30 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index f8023291fb..8d334181f2 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -65,6 +65,8 @@ import UnliftIO.STM data ChatCommand = ChatHelp + | FilesHelp + | GroupsHelp | MarkdownHelp | AddContact | Connect SMPQueueInfo @@ -169,6 +171,8 @@ inputSubscriber = do processChatCommand :: forall m. ChatMonad m => User -> ChatCommand -> m () processChatCommand user@User {userId, profile} = \case ChatHelp -> printToView chatHelpInfo + FilesHelp -> printToView filesHelpInfo + GroupsHelp -> printToView groupsHelpInfo MarkdownHelp -> printToView markdownInfo AddContact -> do (connId, qInfo) <- withAgent createConnection @@ -1046,7 +1050,9 @@ withStore action = chatCommandP :: Parser ChatCommand chatCommandP = - ("/help" <|> "/h") $> ChatHelp + ("/help files" <|> "/help file" <|> "/hf") $> FilesHelp + <|> ("/help groups" <|> "/help group" <|> "/hg") $> GroupsHelp + <|> ("/help" <|> "/h") $> ChatHelp <|> ("/group #" <|> "/group " <|> "/g #" <|> "/g ") *> (NewGroup <$> groupProfile) <|> ("/add #" <|> "/add " <|> "/a #" <|> "/a ") *> (AddMember <$> displayName <* A.space <*> displayName <*> memberRole) <|> ("/join #" <|> "/join " <|> "/j #" <|> "/j ") *> (JoinGroup <$> displayName) @@ -1061,9 +1067,9 @@ chatCommandP = <|> A.char '@' *> (SendMessage <$> displayName <*> (A.space *> A.takeByteString)) <|> ("/file #" <|> "/f #") *> (SendGroupFile <$> displayName <* A.space <*> filePath) <|> ("/file @" <|> "/file " <|> "/f @" <|> "/f ") *> (SendFile <$> displayName <* A.space <*> filePath) - <|> ("/file_receive " <|> "/fr ") *> (ReceiveFile <$> A.decimal <*> optional (A.space *> filePath)) - <|> ("/file_cancel " <|> "/fc ") *> (CancelFile <$> A.decimal) - <|> ("/file_status " <|> "/fs ") *> (FileStatus <$> A.decimal) + <|> ("/freceive " <|> "/fr ") *> (ReceiveFile <$> A.decimal <*> optional (A.space *> filePath)) + <|> ("/fcancel " <|> "/fc ") *> (CancelFile <$> A.decimal) + <|> ("/fstatus " <|> "/fs ") *> (FileStatus <$> A.decimal) <|> ("/markdown" <|> "/m") $> MarkdownHelp <|> ("/profile " <|> "/p ") *> (UpdateProfile <$> userProfile) <|> ("/profile" <|> "/p") $> ShowProfile @@ -1086,5 +1092,5 @@ chatCommandP = memberRole = (" owner" $> GROwner) <|> (" admin" $> GRAdmin) - <|> (" normal" $> GRMember) + <|> (" member" $> GRMember) <|> pure GRAdmin diff --git a/src/Simplex/Chat/Help.hs b/src/Simplex/Chat/Help.hs index 997931e3fe..10b8ae5fe1 100644 --- a/src/Simplex/Chat/Help.hs +++ b/src/Simplex/Chat/Help.hs @@ -1,54 +1,109 @@ {-# LANGUAGE OverloadedStrings #-} -module Simplex.Chat.Help where +module Simplex.Chat.Help + ( chatHelpInfo, + filesHelpInfo, + groupsHelpInfo, + markdownInfo, + ) +where import Data.List (intersperse) +import Data.Text (Text) import Simplex.Chat.Markdown import Simplex.Chat.Styled import System.Console.ANSI.Types +highlight :: Text -> Markdown +highlight = Markdown (Colored Cyan) + +green :: Text -> Markdown +green = Markdown (Colored Green) + +indent :: Markdown +indent = " " + +listHighlight :: [Text] -> Markdown +listHighlight = mconcat . intersperse ", " . map highlight + chatHelpInfo :: [StyledString] chatHelpInfo = map styleMarkdown - [ highlight "Using Simplex chat prototype.", + [ highlight "Using SimpleX chat prototype", "Follow these steps to set up a connection:", "", - Markdown (Colored Green) "Step 1: " <> highlight "/connect" <> " -- Alice adds a contact.", + green "Step 1: " <> highlight "/connect" <> " - Alice adds a contact.", indent <> "Alice should send the invitation printed by the /add command", indent <> "to her contact, Bob, out-of-band, via any trusted channel.", "", - Markdown (Colored Green) "Step 2: " <> highlight "/connect " <> " -- Bob accepts the invitation.", + green "Step 2: " <> highlight "/connect " <> " - Bob accepts the invitation.", indent <> "Bob should use the invitation he received out-of-band.", "", - Markdown (Colored Green) "Step 3: " <> "Bob and Alice are notified that the connection is set up,", + green "Step 3: " <> "Bob and Alice are notified that the connection is set up,", indent <> "both can now send messages:", - indent <> highlight "@bob Hello, Bob!" <> " -- Alice messages Bob (assuming Bob has display name 'bob').", - indent <> highlight "@alice Hey, Alice!" <> " -- Bob replies to Alice.", + indent <> highlight "@bob Hello, Bob!" <> " - Alice messages Bob (assuming Bob has display name 'bob').", + indent <> highlight "@alice Hey, Alice!" <> " - Bob replies to Alice.", "", - Markdown (Colored Green) "Other commands:", - indent <> highlight "/delete " <> " -- deletes contact and all messages with them.", - indent <> highlight "/markdown" <> " -- prints the supported markdown syntax.", + green "To send file:", + indent <> highlight "/file bob ./photo.jpg" <> " - Alice sends file to Bob", + indent <> "File commands: " <> highlight "/help files", "", - "The commands may be abbreviated to a single letter: " <> listCommands ["/a", "/c", "/d", "/h", "/m"] + green "To create group:", + indent <> highlight "/group team" <> " - create group #team", + indent <> "Group commands: " <> highlight "/help groups", + "", + green "Other commands:", + indent <> highlight "/profile " <> " - show user profile", + indent <> highlight "/profile []" <> " - update user profile", + indent <> highlight "/delete " <> " - delete contact and all messages with them", + indent <> highlight "/markdown " <> " - show supported markdown syntax", + indent <> highlight "/quit " <> " - quit chat", + "", + "The commands may be abbreviated to a single letter: " <> listHighlight ["/c", "/f", "/g", "/p", "/h"] <> ", etc." + ] + +filesHelpInfo :: [StyledString] +filesHelpInfo = + map + styleMarkdown + [ green "File transfer commands:", + indent <> highlight "/file @ " <> " - send file to contact.", + indent <> highlight "/file # " <> " - send file to group.", + indent <> highlight "/freceive []" <> " - accept to receive file.", + indent <> highlight "/fcancel " <> " - cancel sending / receiving file.", + indent <> highlight "/fstatus " <> " - show file transfer status.", + "", + "The commands may be abbreviated: " <> listHighlight ["/f", "/fr", "/fc", "/fs"] + ] + +groupsHelpInfo :: [StyledString] +groupsHelpInfo = + map + styleMarkdown + [ green "Group management commands:", + indent <> highlight "/group [] " <> " - create group", + indent <> highlight "/add []" <> " - add contact to group, roles: " <> highlight "owner" <> ", " <> highlight "admin" <> " (default), " <> highlight "member", + indent <> highlight "/join " <> " - accept group invitation", + indent <> highlight "/remove " <> " - remove member from group", + indent <> highlight "/leave " <> " - leave group", + indent <> highlight "/delete " <> " - delete group", + indent <> highlight "/members " <> " - list group members", + indent <> highlight "# " <> " - send message to group", + "", + "The commands may be abbreviated: " <> listHighlight ["/g", "/a", "/j", "/rm", "/l", "/d", "/ms"] ] - where - listCommands = mconcat . intersperse ", " . map highlight - highlight = Markdown (Colored Cyan) - indent = " " markdownInfo :: [StyledString] markdownInfo = map styleMarkdown - [ "Markdown:", - " *bold* - " <> Markdown Bold "bold text", - " _italic_ - " <> Markdown Italic "italic text" <> " (shown as underlined)", - " +underlined+ - " <> Markdown Underline "underlined text", - " ~strikethrough~ - " <> Markdown StrikeThrough "strikethrough text" <> " (shown as inverse)", - " `code snippet` - " <> Markdown Snippet "a + b // no *markdown* here", - " !1 text! - " <> red "red text" <> " (1-6: red, green, blue, yellow, cyan, magenta)", - " #secret# - " <> Markdown Secret "secret text" <> " (can be copy-pasted)" + [ green "Markdown:", + indent <> highlight "*bold* " <> " - " <> Markdown Bold "bold text", + indent <> highlight "_italic_ " <> " - " <> Markdown Italic "italic text" <> " (shown as underlined)", + indent <> highlight "+underlined+ " <> " - " <> Markdown Underline "underlined text", + indent <> highlight "~strikethrough~" <> " - " <> Markdown StrikeThrough "strikethrough text" <> " (shown as inverse)", + indent <> highlight "`code snippet` " <> " - " <> Markdown Snippet "a + b // no *markdown* here", + indent <> highlight "!1 text! " <> " - " <> Markdown (Colored Red) "red text" <> " (1-6: red, green, blue, yellow, cyan, magenta)", + indent <> highlight "#secret# " <> " - " <> Markdown Secret "secret text" <> " (can be copy-pasted)" ] - where - red = Markdown (Colored Red)