diff --git a/src/Simplex/Chat/Help.hs b/src/Simplex/Chat/Help.hs index 1f77617af..8997f150d 100644 --- a/src/Simplex/Chat/Help.hs +++ b/src/Simplex/Chat/Help.hs @@ -270,7 +270,8 @@ settingsInfo = [ green "Chat settings:", indent <> highlight "/incognito on/off " <> " - enable/disable incognito mode", indent <> highlight "/network " <> " - show / set network access options", - indent <> highlight "/smp " <> " - show / set custom SMP servers", + indent <> highlight "/smp " <> " - show / set configured SMP servers", + indent <> highlight "/xftp " <> " - show / set configured XFTP servers", indent <> highlight "/info " <> " - information about contact connection", indent <> highlight "/info # " <> " - information about member connection", indent <> highlight "/(un)mute " <> " - (un)mute contact, the last messages can be printed with /tail command", diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 6937fe818..dfd5d7330 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -49,7 +49,7 @@ import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Encoding import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (dropPrefix, taggedObjectJSON) -import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, ProtocolServer (..), ProtocolTypeI, SProtocolType (..)) +import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, ProtocolServer (..), ProtoServerWithAuth, ProtocolTypeI, SProtocolType (..)) import qualified Simplex.Messaging.Protocol as SMP import Simplex.Messaging.Transport.Client (TransportHost (..)) import Simplex.Messaging.Util (bshow, tshow) @@ -829,18 +829,17 @@ viewUserPrivacy User {userId} User {userId = userId', localDisplayName = n', sho "profile is " <> if isJust viewPwdHash then "hidden" else "visible" ] --- TODO make more generic messages or split viewUserServers :: AUserProtoServers -> Bool -> [StyledString] -viewUserServers (AUPS UserProtoServers {serverProtocol = p, protoServers}) testView = - if testView - then [customServers] - else - [ customServers, - "", - "use " <> highlight (srvCmd <> " test ") <> " to test " <> pName <> " server connection", - "use " <> highlight (srvCmd <> " set ") <> " to switch to custom " <> pName <> " servers", - "use " <> highlight (srvCmd <> " default") <> " to remove custom " <> pName <> " servers and use default" - ] +viewUserServers (AUPS UserProtoServers {serverProtocol = p, protoServers, presetServers}) testView = + customServers <> + if testView + then [] + else + [ "", + "use " <> highlight (srvCmd <> " test ") <> " to test " <> pName <> " server connection", + "use " <> highlight (srvCmd <> " ") <> " to configure " <> pName <> " servers", + "use " <> highlight (srvCmd <> " default") <> " to remove configured " <> pName <> " servers and use presets" + ] <> case p of SPSMP -> ["(chat option " <> highlight' "-s" <> " (" <> highlight' "--server" <> ") has precedence over saved SMP servers for chat session)"] SPXFTP -> ["(chat option " <> highlight' "-xftp-servers" <> " has precedence over saved XFTP servers for chat session)"] @@ -849,8 +848,8 @@ viewUserServers (AUPS UserProtoServers {serverProtocol = p, protoServers}) testV pName = protocolName p customServers = if null protoServers - then "no custom SMP servers saved" - else viewServers protoServers + then ("no " <> pName <> " servers saved, using presets: ") : viewServers id presetServers + else viewServers (\ServerCfg {server} -> server) protoServers protocolName :: ProtocolTypeI p => SProtocolType p -> StyledString protocolName = plain . map toUpper . T.unpack . decodeLatin1 . strEncode @@ -918,8 +917,8 @@ viewConnectionStats ConnectionStats {rcvServers, sndServers} = ["receiving messages via: " <> viewServerHosts rcvServers | not $ null rcvServers] <> ["sending messages via: " <> viewServerHosts sndServers | not $ null sndServers] -viewServers :: ProtocolTypeI p => NonEmpty (ServerCfg p) -> StyledString -viewServers = plain . intercalate ", " . map (B.unpack . strEncode . (\ServerCfg {server} -> server)) . L.toList +viewServers :: ProtocolTypeI p => (a -> ProtoServerWithAuth p) -> NonEmpty a -> [StyledString] +viewServers f = map (plain . B.unpack . strEncode . f) . L.toList viewServerHosts :: [SMPServer] -> StyledString viewServerHosts = plain . intercalate ", " . map showSMPServer diff --git a/tests/ChatTests/Direct.hs b/tests/ChatTests/Direct.hs index 67f6171a1..199001281 100644 --- a/tests/ChatTests/Direct.hs +++ b/tests/ChatTests/Direct.hs @@ -518,7 +518,8 @@ testGetSetSMPServers = alice #$> ("/smp smp://1234-w==:password@smp1.example.im", id, "ok") alice #$> ("/smp", id, "smp://1234-w==:password@smp1.example.im") alice #$> ("/smp smp://2345-w==@smp2.example.im;smp://3456-w==@smp3.example.im:5224", id, "ok") - alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im, smp://3456-w==@smp3.example.im:5224") + alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im") + alice <## "smp://3456-w==@smp3.example.im:5224" alice #$> ("/smp default", id, "ok") alice #$> ("/smp", id, "smp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7001") @@ -547,7 +548,8 @@ testGetSetXFTPServers = alice #$> ("/xftp xftp://1234-w==:password@xftp1.example.im", id, "ok") alice #$> ("/xftp", id, "xftp://1234-w==:password@xftp1.example.im") alice #$> ("/xftp xftp://2345-w==@xftp2.example.im;xftp://3456-w==@xftp3.example.im:5224", id, "ok") - alice #$> ("/xftp", id, "xftp://2345-w==@xftp2.example.im, xftp://3456-w==@xftp3.example.im:5224") + alice #$> ("/xftp", id, "xftp://2345-w==@xftp2.example.im") + alice <## "xftp://3456-w==@xftp3.example.im:5224" alice #$> ("/xftp default", id, "ok") alice #$> ("/xftp", id, "xftp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7002") @@ -1129,7 +1131,8 @@ testCreateUserDefaultServers = testChat2 aliceProfile bobProfile $ \alice _ -> do alice #$> ("/smp smp://2345-w==@smp2.example.im;smp://3456-w==@smp3.example.im:5224", id, "ok") - alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im, smp://3456-w==@smp3.example.im:5224") + alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im") + alice <## "smp://3456-w==@smp3.example.im:5224" alice ##> "/create user alisa" showActiveUser alice "alisa" @@ -1139,7 +1142,8 @@ testCreateUserDefaultServers = -- with same_smp=off alice ##> "/user alice" showActiveUser alice "alice (Alice)" - alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im, smp://3456-w==@smp3.example.im:5224") + alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im") + alice <## "smp://3456-w==@smp3.example.im:5224" alice ##> "/create user same_smp=off alisa2" showActiveUser alice "alisa2" @@ -1151,12 +1155,14 @@ testCreateUserSameServers = testChat2 aliceProfile bobProfile $ \alice _ -> do alice #$> ("/smp smp://2345-w==@smp2.example.im;smp://3456-w==@smp3.example.im:5224", id, "ok") - alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im, smp://3456-w==@smp3.example.im:5224") + alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im") + alice <## "smp://3456-w==@smp3.example.im:5224" alice ##> "/create user same_smp=on alisa" showActiveUser alice "alisa" - alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im, smp://3456-w==@smp3.example.im:5224") + alice #$> ("/smp", id, "smp://2345-w==@smp2.example.im") + alice <## "smp://3456-w==@smp3.example.im:5224" testDeleteUser :: HasCallStack => FilePath -> IO () testDeleteUser =