From 2bc1236a2cd943f89d1612f4da48dd52213c1702 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:33:17 +0000 Subject: [PATCH 1/9] terminal: update help, remove user ID from terminal /smp test command (#1973) * terminal: update help, remove user ID from terminal /smp test command * update mobile api * update help --- .../java/chat/simplex/app/model/SimpleXAPI.kt | 8 +- apps/ios/Shared/Model/SimpleXAPI.swift | 2 +- apps/ios/SimpleXChat/APITypes.swift | 6 +- src/Simplex/Chat.hs | 8 +- src/Simplex/Chat/Controller.hs | 5 +- src/Simplex/Chat/Help.hs | 125 +++++++++++++----- src/Simplex/Chat/View.hs | 1 + tests/ChatTests/Direct.hs | 6 +- 8 files changed, 113 insertions(+), 48 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index 7b836452f..c1571262f 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -549,7 +549,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a suspend fun testSMPServer(smpServer: String): SMPTestFailure? { val userId = chatModel.currentUser.value?.userId ?: run { throw Exception("testSMPServer: no current user") } - val r = sendCmd(CC.TestSMPServer(userId, smpServer)) + val r = sendCmd(CC.APITestSMPServer(userId, smpServer)) return when (r) { is CR.SmpTestResult -> r.smpTestFailure else -> { @@ -1757,7 +1757,7 @@ sealed class CC { class APIGetGroupLink(val groupId: Long): CC() class APIGetUserSMPServers(val userId: Long): CC() class APISetUserSMPServers(val userId: Long, val smpServers: List): CC() - class TestSMPServer(val userId: Long, val smpServer: String): CC() + class APITestSMPServer(val userId: Long, val smpServer: String): CC() class APISetChatItemTTL(val userId: Long, val seconds: Long?): CC() class APIGetChatItemTTL(val userId: Long): CC() class APISetNetworkConfig(val networkConfig: NetCfg): CC() @@ -1832,7 +1832,7 @@ sealed class CC { is APIGetGroupLink -> "/_get link #$groupId" is APIGetUserSMPServers -> "/_smp $userId" is APISetUserSMPServers -> "/_smp $userId ${smpServersStr(smpServers)}" - is TestSMPServer -> "/smp test $userId $smpServer" + is APITestSMPServer -> "/_smp test $userId $smpServer" is APISetChatItemTTL -> "/_ttl $userId ${chatItemTTLStr(seconds)}" is APIGetChatItemTTL -> "/_ttl $userId" is APISetNetworkConfig -> "/_network ${json.encodeToString(networkConfig)}" @@ -1908,7 +1908,7 @@ sealed class CC { is APIGetGroupLink -> "apiGetGroupLink" is APIGetUserSMPServers -> "apiGetUserSMPServers" is APISetUserSMPServers -> "apiSetUserSMPServers" - is TestSMPServer -> "testSMPServer" + is APITestSMPServer -> "testSMPServer" is APISetChatItemTTL -> "apiSetChatItemTTL" is APIGetChatItemTTL -> "apiGetChatItemTTL" is APISetNetworkConfig -> "/apiSetNetworkConfig" diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 866b09a64..458397702 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -344,7 +344,7 @@ func setUserSMPServers(smpServers: [ServerCfg]) async throws { func testSMPServer(smpServer: String) async throws -> Result<(), SMPTestFailure> { guard let userId = ChatModel.shared.currentUser?.userId else { throw RuntimeError("testSMPServer: no current user") } - let r = await chatSendCmd(.testSMPServer(userId: userId, smpServer: smpServer)) + let r = await chatSendCmd(.apiTestSMPServer(userId: userId, smpServer: smpServer)) if case let .smpTestResult(_, testFailure) = r { if let t = testFailure { return .failure(t) diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index 5a562df10..7d6d586c5 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -51,7 +51,7 @@ public enum ChatCommand { case apiGetGroupLink(groupId: Int64) case apiGetUserSMPServers(userId: Int64) case apiSetUserSMPServers(userId: Int64, smpServers: [ServerCfg]) - case testSMPServer(userId: Int64, smpServer: String) + case apiTestSMPServer(userId: Int64, smpServer: String) case apiSetChatItemTTL(userId: Int64, seconds: Int64?) case apiGetChatItemTTL(userId: Int64) case apiSetNetworkConfig(networkConfig: NetCfg) @@ -139,7 +139,7 @@ public enum ChatCommand { case let .apiGetGroupLink(groupId): return "/_get link #\(groupId)" case let .apiGetUserSMPServers(userId): return "/_smp \(userId)" case let .apiSetUserSMPServers(userId, smpServers): return "/_smp \(userId) \(smpServersStr(smpServers: smpServers))" - case let .testSMPServer(userId, smpServer): return "/smp test \(userId) \(smpServer)" + case let .apiTestSMPServer(userId, smpServer): return "/_smp test \(userId) \(smpServer)" case let .apiSetChatItemTTL(userId, seconds): return "/_ttl \(userId) \(chatItemTTLStr(seconds: seconds))" case let .apiGetChatItemTTL(userId): return "/_ttl \(userId)" case let .apiSetNetworkConfig(networkConfig): return "/_network \(encodeJSON(networkConfig))" @@ -232,7 +232,7 @@ public enum ChatCommand { case .apiGetGroupLink: return "apiGetGroupLink" case .apiGetUserSMPServers: return "apiGetUserSMPServers" case .apiSetUserSMPServers: return "apiSetUserSMPServers" - case .testSMPServer: return "testSMPServer" + case .apiTestSMPServer: return "testSMPServer" case .apiSetChatItemTTL: return "apiSetChatItemTTL" case .apiGetChatItemTTL: return "apiGetChatItemTTL" case .apiSetNetworkConfig: return "apiSetNetworkConfig" diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 1649c4f4f..a2c951642 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -824,8 +824,10 @@ processChatCommand = \case ok user SetUserSMPServers smpServersConfig -> withUser $ \User {userId} -> processChatCommand $ APISetUserSMPServers userId smpServersConfig - TestSMPServer userId smpServer -> withUserId userId $ \user -> + APITestSMPServer userId smpServer -> withUserId userId $ \user -> CRSmpTestResult user <$> withAgent (\a -> testSMPServerConnection a (aUserId user) smpServer) + TestSMPServer smpServer -> withUser $ \User {userId} -> + processChatCommand $ APITestSMPServer userId smpServer APISetChatItemTTL userId newTTL_ -> withUser' $ \user -> do checkSameUser userId user checkStoreNotChanged $ @@ -4000,7 +4002,8 @@ chatCommandP = "/smp_servers " *> (SetUserSMPServers . SMPServersConfig . map toServerCfg <$> smpServersP), "/smp_servers" $> GetUserSMPServers, "/smp default" $> SetUserSMPServers (SMPServersConfig []), - "/smp test " *> (TestSMPServer <$> A.decimal <* A.space <*> strP), + "/_smp test " *> (APITestSMPServer <$> A.decimal <* A.space <*> strP), + "/smp test " *> (TestSMPServer <$> strP), "/_smp " *> (APISetUserSMPServers <$> A.decimal <* A.space <*> jsonP), "/smp " *> (SetUserSMPServers . SMPServersConfig . map toServerCfg <$> smpServersP), "/_smp " *> (APIGetUserSMPServers <$> A.decimal), @@ -4035,6 +4038,7 @@ chatCommandP = "/enable #" *> (EnableGroupMember <$> displayName <* A.space <* char_ '@' <*> displayName), ("/help files" <|> "/help file" <|> "/hf") $> ChatHelp HSFiles, ("/help groups" <|> "/help group" <|> "/hg") $> ChatHelp HSGroups, + ("/help contacts" <|> "/help contact" <|> "/hc") $> ChatHelp HSContacts, ("/help address" <|> "/ha") $> ChatHelp HSMyAddress, ("/help messages" <|> "/hm") $> ChatHelp HSMessages, ("/help settings" <|> "/hs") $> ChatHelp HSSettings, diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index c6a560d52..67a905045 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -170,7 +170,7 @@ data ChatController = ChatController logFilePath :: Maybe FilePath } -data HelpSection = HSMain | HSFiles | HSGroups | HSMyAddress | HSMarkdown | HSMessages | HSSettings +data HelpSection = HSMain | HSFiles | HSGroups | HSContacts | HSMyAddress | HSMarkdown | HSMessages | HSSettings deriving (Show, Generic) instance ToJSON HelpSection where @@ -244,7 +244,8 @@ data ChatCommand | GetUserSMPServers | APISetUserSMPServers UserId SMPServersConfig | SetUserSMPServers SMPServersConfig - | TestSMPServer UserId SMPServerWithAuth + | APITestSMPServer UserId SMPServerWithAuth + | TestSMPServer SMPServerWithAuth | APISetChatItemTTL UserId (Maybe Int64) | SetChatItemTTL (Maybe Int64) | APIGetChatItemTTL UserId diff --git a/src/Simplex/Chat/Help.hs b/src/Simplex/Chat/Help.hs index b9650b36b..486e9c711 100644 --- a/src/Simplex/Chat/Help.hs +++ b/src/Simplex/Chat/Help.hs @@ -6,6 +6,7 @@ module Simplex.Chat.Help chatHelpInfo, filesHelpInfo, groupsHelpInfo, + contactsHelpInfo, myAddressHelpInfo, messagesHelpInfo, markdownInfo, @@ -84,7 +85,7 @@ chatHelpInfo = green "Create your address: " <> highlight "/address", "", green "Other commands:", - indent <> highlight "/help " <> " - help on: " <> listHighlight ["messages", "files", "groups", "address", "settings"], + indent <> highlight "/help " <> " - help on: " <> listHighlight ["groups", "contacts", "messages", "files", "address", "settings"], indent <> highlight "/profile " <> " - show / update user profile", indent <> highlight "/delete " <> " - delete contact and all messages with them", indent <> highlight "/chats " <> " - most recent chats", @@ -100,13 +101,15 @@ filesHelpInfo = map styleMarkdown [ green "File transfer commands:", - indent <> highlight "/file @ " <> " - send file to contact", - indent <> highlight "/file # " <> " - send file to group", - indent <> highlight "/image [] " <> " - send file as image to @contact or #group", - indent <> highlight "/freceive []" <> " - accept to receive file", - indent <> highlight "/fforward [] " <> " - forward received file to @contact or #group", - indent <> highlight "/fcancel " <> " - cancel sending / receiving file", - indent <> highlight "/fstatus " <> " - show file transfer status", + indent <> highlight "/file @ " <> " - send file to contact", + indent <> highlight "/file # " <> " - send file to group", + indent <> highlight "/image [] " <> " - send file as image to @contact or #group", + indent <> highlight "/freceive [] " <> " - accept to receive file", + indent <> highlight "/fforward [] " <> " - forward received file to @contact or #group", + indent <> highlight "/fcancel " <> " - cancel sending / receiving file", + indent <> highlight "/fstatus " <> " - show file transfer status", + indent <> highlight "/imgf @ " <> " - forward received image to contact", + indent <> highlight "/imgf # " <> " - forward received image to group", "", "The commands may be abbreviated: " <> listHighlight ["/f", "/img", "/fr", "/ff", "/fc", "/fs"] ] @@ -115,34 +118,87 @@ 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 "/gp " <> " - view group profile", - indent <> highlight "/gp [] " <> " - update group profile", - indent <> highlight "/group_descr [] " <> " - update/remove group description", - indent <> highlight "/groups " <> " - list groups", - indent <> highlight "# " <> " - send message to group", - indent <> highlight "/create link # " <> " - create public group link", + [ green "Group 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 "/members " <> " - list group members", + indent <> highlight "/remove " <> " - remove member from group", + indent <> highlight "/leave " <> " - leave group", + indent <> highlight "/clear # " <> " - clear all messages in the group locally", + indent <> highlight "/delete # " <> " - delete group and all messages", + indent <> highlight "/gp " <> " - view group profile", + indent <> highlight "/gp [] " <> " - update group profile names", + indent <> highlight "/group_descr [] " <> " - update/remove group description", + indent <> highlight "/groups " <> " - list groups", + indent <> highlight "# " <> " - send message to group", + indent <> highlight "/create link # " <> " - create public group link", + "", + green "Mute group messages:", + indent <> highlight "/mute # " <> " - do not show contact's messages", + indent <> highlight "/unmute # " <> " - show contact's messages", + "", + green "Group member connection and security:", + indent <> highlight "/code # " <> " - show member's security code", + indent <> highlight "/verify # " <> " - verify member's security code", + indent <> highlight "/verify # " <> " - clear security code verification", + indent <> highlight "/info # " <> " - info about member connection", + indent <> highlight "/switch # " <> " - switch receiving messages to another SMP relay", + "", + green "Group chat preferences:", + indent <> highlight "/set voice # on/off " <> " - enable/disable voice messages", + indent <> highlight "/set delete # on/off " <> " - enable/disable full message deletion", + indent <> highlight "/set direct # on/off " <> " - enable/disable direct messages to other members", + indent <> highlight "/set disappear # on