Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

update help - file transfer and groups #98

Merged
merged 4 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Simplex/Chat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import UnliftIO.STM

data ChatCommand
= ChatHelp
| FilesHelp
| GroupsHelp
| MarkdownHelp
| AddContact
| Connect SMPQueueInfo
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
94 changes: 70 additions & 24 deletions src/Simplex/Chat/Help.hs
Original file line number Diff line number Diff line change
@@ -1,54 +1,100 @@
{-# 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.",
"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 <invitation>" <> " -- Bob accepts the invitation.",
green "Step 2: " <> highlight "/connect <invitation>" <> " - 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 <name>" <> " -- deletes contact and all messages with them.",
indent <> highlight "/markdown" <> " -- prints the supported markdown syntax.",
"Simplex chat supports " <> green "file transfer" <> " and " <> green "groups" <> " functionality:",
indent <> highlight "/help_files " <> " - show file transfer help.",
indent <> highlight "/help_groups " <> " - show groups help.",
"",
"The commands may be abbreviated to a single letter: " <> listCommands ["/a", "/c", "/d", "/h", "/m"]
green "Other commands:",
indent <> highlight "/delete <contact>" <> " - delete contact and all messages with them.",
indent <> highlight "/profile " <> " - show / update user profile.",
indent <> highlight "/markdown " <> " - show supported markdown syntax.",
indent <> highlight "/quit " <> " - quit chat.",
"",
"The commands may be abbreviated to a single letter (first letters): " <> listHighlight ["/c", "/d", "/p", "/h", "/hf", "/hg"] <> ", etc."
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
]

filesHelpInfo :: [StyledString]
filesHelpInfo =
map
styleMarkdown
[ green "File transfer commands:",
indent <> highlight "/file @<contact> <file_path> " <> " - send file to contact.",
indent <> highlight "/file #<group> <file_path> " <> " - send file to group.",
indent <> highlight "/file_receive <file_id> [<file_path>]" <> " - accept to receive file.",
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
indent <> highlight "/file_cancel <file_id> " <> " - cancel sending file.",
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
indent <> highlight "/file_status <file_id> " <> " - show file transfer status."
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
]

groupsHelpInfo :: [StyledString]
groupsHelpInfo =
map
styleMarkdown
[ green "Group management commands:",
indent <> highlight "/group <group> [<full_name>] " <> " - create group.",
indent <> highlight "/add <group> <contact> [<role>]" <> " - add contact to group as a member, roles: " <> listHighlight ["owner", "admin", "normal"] <> ".",
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
indent <> highlight "/join <group> " <> " - accept group invitation.",
indent <> highlight "/remove <group> <member> " <> " - remove member from group.",
indent <> highlight "/leave <group> " <> " - leave group.",
indent <> highlight "/delete <group> " <> " - delete group.",
indent <> highlight "/members <group> " <> " - list group members.",
indent <> highlight "#<group> <message> " <> " - send message to group."
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
]
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)