diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 3f5fbcd3f5..d40e7ab302 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -41,7 +41,7 @@ import qualified Data.Map.Strict as M import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, listToMaybe, mapMaybe, maybeToList) import Data.Text (Text) import qualified Data.Text as T -import Data.Time (NominalDiffTime, addUTCTime) +import Data.Time (NominalDiffTime, addUTCTime, defaultTimeLocale, formatTime) import Data.Time.Clock (UTCTime, diffUTCTime, getCurrentTime, nominalDiffTimeToSeconds) import Data.Time.Clock.System (SystemTime, systemToUTCTime) import Data.Time.LocalTime (getCurrentTimeZone, getZonedTime) @@ -354,6 +354,10 @@ processChatCommand = \case asks incognitoMode >>= atomically . (`writeTVar` onOff) ok_ APIExportArchive cfg -> checkChatStopped $ exportArchive cfg >> ok_ + ExportArchive -> do + ts <- liftIO getCurrentTime + let filePath = "simplex-chat." <> formatTime defaultTimeLocale "%FT%H%M%SZ" ts <> ".zip" + processChatCommand $ APIExportArchive $ ArchiveConfig filePath Nothing Nothing APIImportArchive cfg -> withStoreChanged $ importArchive cfg APIDeleteStorage -> withStoreChanged deleteStorage APIStorageEncryption cfg -> withStoreChanged $ sqlCipherExport cfg @@ -3974,8 +3978,9 @@ chatCommandP = "/_app activate" $> APIActivateChat, "/_app suspend " *> (APISuspendChat <$> A.decimal), "/_resubscribe all" $> ResubscribeAllConnections, - "/_files_folder " *> (SetFilesFolder <$> filePath), + ("/_files_folder " <|> "/files_folder ") *> (SetFilesFolder <$> filePath), "/_db export " *> (APIExportArchive <$> jsonP), + "/db export" $> ExportArchive, "/_db import " *> (APIImportArchive <$> jsonP), "/_db delete" $> APIDeleteStorage, "/_db encryption " *> (APIStorageEncryption <$> jsonP), @@ -4067,6 +4072,7 @@ chatCommandP = ("/help address" <|> "/ha") $> ChatHelp HSMyAddress, ("/help messages" <|> "/hm") $> ChatHelp HSMessages, ("/help settings" <|> "/hs") $> ChatHelp HSSettings, + ("/help db" <|> "/hd") $> ChatHelp HSDatabase, ("/help" <|> "/h") $> ChatHelp HSMain, ("/group " <|> "/g ") *> char_ '#' *> (NewGroup <$> groupProfile), "/_group " *> (APINewGroup <$> A.decimal <* A.space <*> jsonP), diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index e9b499de00..103fbb0575 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -171,7 +171,7 @@ data ChatController = ChatController logFilePath :: Maybe FilePath } -data HelpSection = HSMain | HSFiles | HSGroups | HSContacts | HSMyAddress | HSMarkdown | HSMessages | HSSettings +data HelpSection = HSMain | HSFiles | HSGroups | HSContacts | HSMyAddress | HSMarkdown | HSMessages | HSSettings | HSDatabase deriving (Show, Generic) instance ToJSON HelpSection where @@ -194,6 +194,7 @@ data ChatCommand | SetFilesFolder FilePath | SetIncognito Bool | APIExportArchive ArchiveConfig + | ExportArchive | APIImportArchive ArchiveConfig | APIDeleteStorage | APIStorageEncryption DBEncryptionConfig diff --git a/src/Simplex/Chat/Help.hs b/src/Simplex/Chat/Help.hs index 7334b32a8e..37770d1bd1 100644 --- a/src/Simplex/Chat/Help.hs +++ b/src/Simplex/Chat/Help.hs @@ -11,6 +11,7 @@ module Simplex.Chat.Help messagesHelpInfo, markdownInfo, settingsInfo, + databaseHelpInfo, ) where @@ -85,7 +86,7 @@ chatHelpInfo = green "Create your address: " <> highlight "/address", "", green "Other commands:", - indent <> highlight "/help " <> " - help on: " <> listHighlight ["groups", "contacts", "messages", "files", "address", "settings"], + indent <> highlight "/help " <> " - help on: " <> listHighlight ["groups", "contacts", "messages", "files", "address", "settings", "db"], indent <> highlight "/profile " <> " - show / update user profile", indent <> highlight "/delete " <> " - delete contact and all messages with them", indent <> highlight "/chats " <> " - most recent chats", @@ -276,3 +277,17 @@ settingsInfo = indent <> highlight "/get stats " <> " - get usage statistics", indent <> highlight "/reset stats " <> " - reset usage statistics" ] + +databaseHelpInfo :: [StyledString] +databaseHelpInfo = + map + styleMarkdown + [ green "Database export:", + indent <> highlight "/db export " <> " - create database export file that can be imported in mobile apps", + indent <> highlight "/files_folder " <> " - set files folder path to include app files in the exported archive", + "", + green "Database encryption:", + indent <> highlight "/db encrypt " <> " - encrypt chat database with key/passphrase", + indent <> highlight "/db key " <> " - change the key of the encrypted app database", + indent <> highlight "/db decrypt " <> " - decrypt chat database" + ] diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 0535e5a464..9f9524ccfd 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -99,6 +99,7 @@ responseToView user_ ChatConfig {logLevel, testView} liveItems ts = \case HSMessages -> messagesHelpInfo HSMarkdown -> markdownInfo HSSettings -> settingsInfo + HSDatabase -> databaseHelpInfo CRWelcome user -> chatWelcome user CRContactsList u cs -> ttyUser u $ viewContactsList cs CRUserContactLink u UserContactLink {connReqContact, autoAccept} -> ttyUser u $ connReqContact_ "Your chat address:" connReqContact <> autoAcceptStatus_ autoAccept