mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-22 15:22:07 +00:00
iterate on /goal
This commit is contained in:
1 parent
8028247e87
commit
8706c99063
6 files changed
+76
-134
No files matched your search
@@ -1463,15 +1463,6 @@ enum ConnectionPlan: Decodable, Hashable {
|
||||
case groupLink(groupLinkPlan: GroupLinkPlan, nameWarning_: NameWarning?)
|
||||
case nameNotConnectable(simplexDomain: SimplexDomain, nameWarning: NameWarning)
|
||||
case error(chatError: ChatError)
|
||||
|
||||
var nameWarning: NameWarning? {
|
||||
switch self {
|
||||
case let .contactAddress(_, warning): warning
|
||||
case let .groupLink(_, warning): warning
|
||||
case let .nameNotConnectable(_, warning): warning
|
||||
default: nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum NameWarning: Decodable, Hashable {
|
||||
|
||||
@@ -1344,8 +1344,6 @@ private func showOpenKnownGroupAlert(
|
||||
)
|
||||
}
|
||||
|
||||
private let simplexNamesHowToURL = "https://simplex.domains/#testing"
|
||||
|
||||
private func nameDate(_ date: Date) -> String {
|
||||
date.formatted(date: .long, time: .omitted)
|
||||
}
|
||||
@@ -1375,7 +1373,7 @@ private func showNameWarningAlert(
|
||||
return actions
|
||||
})
|
||||
}
|
||||
let openHowTo = { openBrowserAlert(uri: simplexNamesHowToURL) }
|
||||
let openHowTo = { openBrowserAlert(uri: "https://simplex.domains/#testing") }
|
||||
let register = (title: NSLocalizedString("Register", comment: "alert action"), handler: openHowTo)
|
||||
switch warning {
|
||||
case let .expired(expiredAt, graceUntil):
|
||||
@@ -1504,8 +1502,12 @@ func planAndConnect(
|
||||
info.shortStr
|
||||
)
|
||||
}
|
||||
let nameDomain: SimplexDomain? = if case let .nameNotConnectable(simplexDomain, _) = connectionPlan { simplexDomain } else { planSimplexName?.nameDomain }
|
||||
if let nameWarning = connectionPlan.nameWarning, let nameDomain {
|
||||
let (nameDomain, nameWarning): (SimplexDomain?, NameWarning?) = switch connectionPlan {
|
||||
case let .nameNotConnectable(simplexDomain, warning): (simplexDomain, warning)
|
||||
case let .contactAddress(_, warning), let .groupLink(_, warning): (planSimplexName?.nameDomain, warning)
|
||||
default: (nil, nil)
|
||||
}
|
||||
if let nameWarning, let nameDomain {
|
||||
await MainActor.run {
|
||||
var openExisting: (() -> Void)? = nil
|
||||
switch connectionPlan {
|
||||
@@ -1538,8 +1540,6 @@ func planAndConnect(
|
||||
return
|
||||
}
|
||||
switch connectionPlan {
|
||||
case .nameNotConnectable:
|
||||
break
|
||||
case let .invitationLink(ilp):
|
||||
switch ilp {
|
||||
case let .ok(contactSLinkData_, ownerVerification):
|
||||
@@ -1835,6 +1835,8 @@ func planAndConnect(
|
||||
}
|
||||
}
|
||||
}
|
||||
case .nameNotConnectable:
|
||||
break
|
||||
case let .error(chatError):
|
||||
logger.debug("planAndConnect, .error \(chatErrorString(chatError))")
|
||||
showAskCurrentOrIncognitoProfileSheet(
|
||||
|
||||
-7
@@ -7445,13 +7445,6 @@ sealed class ConnectionPlan {
|
||||
@Serializable @SerialName("groupLink") class GroupLink(val groupLinkPlan: GroupLinkPlan, val nameWarning_: NameWarning? = null): ConnectionPlan()
|
||||
@Serializable @SerialName("nameNotConnectable") class NameNotConnectable(val simplexDomain: SimplexDomain, val nameWarning: NameWarning): ConnectionPlan()
|
||||
@Serializable @SerialName("error") class Error(val chatError: ChatError): ConnectionPlan()
|
||||
|
||||
fun nameWarning(): NameWarning? = when (this) {
|
||||
is ContactAddress -> nameWarning_
|
||||
is GroupLink -> nameWarning_
|
||||
is NameNotConnectable -> nameWarning
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
|
||||
+36
-34
@@ -3,7 +3,6 @@ package chat.simplex.common.views.newchat
|
||||
import SectionItemView
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -70,9 +69,7 @@ private fun namePrice(price: NamePrice): String {
|
||||
return String.format(generalGetString(MR.strings.simplex_name_price_for_years), dollars, price.years)
|
||||
}
|
||||
|
||||
private fun openNameHowTo(uriHandler: UriHandler) = openBrowserAlert(SIMPLEX_NAMES_HOWTO_URL, uriHandler)
|
||||
|
||||
private const val SIMPLEX_NAMES_HOWTO_URL = "https://simplex.domains/#testing"
|
||||
private fun openNameHowTo(uriHandler: UriHandler) = openBrowserAlert("https://simplex.domains/#testing", uriHandler)
|
||||
|
||||
private fun showNameWarningAlert(
|
||||
rhId: Long?,
|
||||
@@ -82,33 +79,37 @@ private fun showNameWarningAlert(
|
||||
cleanup: (() -> Unit)?
|
||||
) {
|
||||
val nameStr = domain.fullDomainName
|
||||
val ok = generalGetString(MR.strings.ok)
|
||||
fun dismiss() {
|
||||
AlertManager.privacySensitive.hideAlert()
|
||||
cleanup?.invoke()
|
||||
}
|
||||
fun buttons(action: Pair<String, (UriHandler) -> Unit>?): @Composable () -> Unit = {
|
||||
val uriHandler = LocalUriHandler.current
|
||||
Column {
|
||||
if (action != null) {
|
||||
SectionItemView({ dismiss(); action.second(uriHandler) }) {
|
||||
Text(action.first, Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
if (openExistingChat != null) {
|
||||
SectionItemView({ dismiss(); openExistingChat() }) {
|
||||
Text(generalGetString(MR.strings.connect_plan_open_existing_chat), Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
SectionItemView(::dismiss) {
|
||||
Text(ok, Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun alert(title: String, text: String, action: Pair<String, (UriHandler) -> Unit>? = null) {
|
||||
AlertManager.privacySensitive.showAlertDialogButtonsColumn(title = title, text = text, onDismissRequest = { cleanup?.invoke() }, hostDevice = hostDevice(rhId), buttons = buttons(action))
|
||||
AlertManager.privacySensitive.showAlertDialogButtonsColumn(
|
||||
title = title,
|
||||
text = text,
|
||||
buttons = {
|
||||
val uriHandler = LocalUriHandler.current
|
||||
Column {
|
||||
if (action != null) {
|
||||
SectionItemView({ dismiss(); action.second(uriHandler) }) {
|
||||
Text(action.first, Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
if (openExistingChat != null) {
|
||||
SectionItemView({ dismiss(); openExistingChat() }) {
|
||||
Text(generalGetString(MR.strings.connect_plan_open_existing_chat), Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
SectionItemView(::dismiss) {
|
||||
Text(generalGetString(MR.strings.ok), Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
},
|
||||
onDismissRequest = cleanup,
|
||||
hostDevice = hostDevice(rhId),
|
||||
)
|
||||
}
|
||||
val register = generalGetString(MR.strings.simplex_name_register) to { uh: UriHandler -> openNameHowTo(uh) }
|
||||
val register = generalGetString(MR.strings.simplex_name_register) to ::openNameHowTo
|
||||
when (warning) {
|
||||
is NameWarning.Expired -> alert(
|
||||
generalGetString(MR.strings.simplex_name_expired),
|
||||
@@ -119,7 +120,7 @@ private fun showNameWarningAlert(
|
||||
generalGetString(MR.strings.simplex_name_own_expired),
|
||||
if (warning.graceUntil != null) String.format(generalGetString(MR.strings.simplex_name_own_expired_desc), nameStr, nameDate(warning.expiredAt), nameDate(warning.graceUntil))
|
||||
else String.format(generalGetString(MR.strings.simplex_name_own_expired_no_date_desc), nameStr, nameDate(warning.expiredAt)),
|
||||
generalGetString(MR.strings.simplex_name_renew) to { uh: UriHandler -> openNameHowTo(uh) }
|
||||
generalGetString(MR.strings.simplex_name_renew) to ::openNameHowTo
|
||||
)
|
||||
is NameWarning.Available -> alert(
|
||||
generalGetString(MR.strings.simplex_name_not_registered),
|
||||
@@ -134,7 +135,7 @@ private fun showNameWarningAlert(
|
||||
is NameWarning.OwnAvailable -> alert(
|
||||
generalGetString(MR.strings.simplex_name_own_expired),
|
||||
String.format(generalGetString(MR.strings.simplex_name_own_available_desc), nameStr, namePrice(warning.price)),
|
||||
generalGetString(MR.strings.simplex_name_re_register) to { uh: UriHandler -> openNameHowTo(uh) }
|
||||
generalGetString(MR.strings.simplex_name_re_register) to ::openNameHowTo
|
||||
)
|
||||
NameWarning.ReservedForCommunity -> alert(
|
||||
generalGetString(MR.strings.simplex_name_not_registered),
|
||||
@@ -182,14 +183,15 @@ private suspend fun planAndConnectTask(
|
||||
val label = if (it.nameType == SimplexNameType.publicGroup) MR.strings.connect_plan_join_name else MR.strings.connect_plan_connect_to_name
|
||||
generalGetString(label).format(it.shortStr)
|
||||
}
|
||||
val nameWarning = connectionPlan.nameWarning()
|
||||
val nameDomain = when (connectionPlan) {
|
||||
is ConnectionPlan.NameNotConnectable -> connectionPlan.simplexDomain
|
||||
else -> planSimplexName?.nameDomain
|
||||
val (nameDomain, nameWarning) = when (connectionPlan) {
|
||||
is ConnectionPlan.NameNotConnectable -> connectionPlan.simplexDomain to connectionPlan.nameWarning
|
||||
is ConnectionPlan.ContactAddress -> planSimplexName?.nameDomain to connectionPlan.nameWarning_
|
||||
is ConnectionPlan.GroupLink -> planSimplexName?.nameDomain to connectionPlan.nameWarning_
|
||||
else -> null to null
|
||||
}
|
||||
if (nameWarning != null && nameDomain != null) {
|
||||
val knownContact = (connectionPlan as? ConnectionPlan.ContactAddress)?.contactAddressPlan.let { it as? ContactAddressPlan.Known }?.contact
|
||||
val knownGroup = (connectionPlan as? ConnectionPlan.GroupLink)?.groupLinkPlan.let { it as? GroupLinkPlan.Known }?.groupInfo
|
||||
val knownContact = ((connectionPlan as? ConnectionPlan.ContactAddress)?.contactAddressPlan as? ContactAddressPlan.Known)?.contact
|
||||
val knownGroup = ((connectionPlan as? ConnectionPlan.GroupLink)?.groupLinkPlan as? GroupLinkPlan.Known)?.groupInfo
|
||||
var openExisting: (() -> Unit)? = null
|
||||
if (knownContact != null) {
|
||||
if (chatModel.getContactChat(knownContact.contactId) == null) {
|
||||
@@ -212,7 +214,6 @@ private suspend fun planAndConnectTask(
|
||||
return completable
|
||||
}
|
||||
when (connectionPlan) {
|
||||
is ConnectionPlan.NameNotConnectable -> {}
|
||||
is ConnectionPlan.InvitationLink -> when (connectionPlan.invitationLinkPlan) {
|
||||
is InvitationLinkPlan.Ok ->
|
||||
if (connectionPlan.invitationLinkPlan.contactSLinkData_ != null) {
|
||||
@@ -520,6 +521,7 @@ private suspend fun planAndConnectTask(
|
||||
}
|
||||
}
|
||||
}
|
||||
is ConnectionPlan.NameNotConnectable -> {}
|
||||
is ConnectionPlan.Error -> {
|
||||
Log.d(TAG, "planAndConnect, error ${connectionPlan.chatError}")
|
||||
askCurrentOrIncognitoProfileAlert(
|
||||
|
||||
+31
-76
@@ -39,11 +39,9 @@ chatNamesTests = do
|
||||
it "connect by name resolving to direct contact (primary) and channel" testConnectByNameContactAndChannel
|
||||
it "connect by name resolving to business (primary) and channel" testConnectByNameBusinessAndChannel
|
||||
describe "connection plan: the name lookup answers" $ do
|
||||
it "reserved for community" testPlanNameReservedCommunity
|
||||
it "reserved for another reason" testPlanNameReservedOther
|
||||
it "registered with no usable link" testPlanNameNoValidLink
|
||||
it "known chat, nothing actionable" testPlanKnownNameLive
|
||||
it "known chat, name expired" testPlanKnownNameExpired
|
||||
it "known chat, name moved to a new address" testPlanKnownNameAddressChanged
|
||||
it "known chat, name now available" testPlanKnownNameAvailable
|
||||
it "known chat and own name, name without link or reserved" testPlanKnownNameReserved
|
||||
@@ -52,12 +50,13 @@ chatNamesTests = do
|
||||
it "own channel expired, joined channel moved to a new channel" testPlanChannelNameMoved
|
||||
it "known chat, resolved over a day ago or past expiry" testPlanKnownNameStale
|
||||
it "no local chat, resolved on every call" testPlanNameResolvedEveryCall
|
||||
it "own name, live" testPlanOwnNameLive
|
||||
it "own name, expired" testPlanOwnNameExpired
|
||||
it "own name, now available" testPlanOwnNameAvailable
|
||||
it "the request failed" testPlanNameResolverFailed
|
||||
it "resolve=never: local hit and miss" testPlanNameResolveNever
|
||||
describe "name warnings" nameWarningTests
|
||||
describe "name warnings" $ do
|
||||
it "warning for a name with no local chat" $ \_ -> testNameLinkOrWarning
|
||||
it "warning for own name" $ \_ -> testOwnNameWarning
|
||||
|
||||
testConnectByName :: HasCallStack => TestParams -> IO ()
|
||||
testConnectByName ps = withSmpServerAndNames $ \reg ->
|
||||
@@ -254,6 +253,10 @@ testConnectByNameChannelAndContact ps = withSmpServerAndNames $ \reg ->
|
||||
alice <## "updated public group access: domain=team.simplex"
|
||||
cath <## "alice updated group #team: (signed)"
|
||||
cath <## "updated public group access: domain=team.simplex"
|
||||
bob ##> "/_connect plan 1 team.simplex"
|
||||
bob <## "group link: ok to connect via relays"
|
||||
_ <- getTermLine bob
|
||||
bob <## "You can also connect to @team.simplex in direct chat"
|
||||
bob ##> "/c #team.simplex"
|
||||
bob <## "#team: connection started"
|
||||
concurrentlyN_
|
||||
@@ -270,7 +273,7 @@ testConnectByNameChannelAndContact ps = withSmpServerAndNames $ \reg ->
|
||||
bob <## "group link: known group #team"
|
||||
bob <## "SimpleX name: #team (verified)"
|
||||
bob <## "use #team <message> to send messages"
|
||||
withCCTransaction bob $ \db -> DB.execute_ db "UPDATE groups SET group_domain_resolved_at = datetime('now', '-2 days')"
|
||||
setGroupNamesStale bob
|
||||
bob ##> "/_connect plan 1 team.simplex"
|
||||
bob <## "group link: known group #team"
|
||||
bob <## "SimpleX name: #team (verified)"
|
||||
@@ -281,7 +284,7 @@ testConnectByNameChannelAndContact ps = withSmpServerAndNames $ \reg ->
|
||||
bob <## "SimpleX name: #team (verified)"
|
||||
bob <## "use #team <message> to send messages"
|
||||
registerName reg teamName (contactNameRecord "team.simplex" (T.pack contactLink))
|
||||
withCCTransaction bob $ \db -> DB.execute_ db "UPDATE groups SET group_domain_resolved_at = datetime('now', '-2 days')"
|
||||
setGroupNamesStale bob
|
||||
bob ##> "/_connect plan 1 team.simplex"
|
||||
bob <## "group link: known group #team"
|
||||
bob <## "SimpleX name: #team (verified)"
|
||||
@@ -351,14 +354,11 @@ testConnectByNameBusinessAndChannel ps = withSmpServerAndNames $ \reg ->
|
||||
bob ##> "/_connect plan 1 @biz.simplex resolve=never"
|
||||
bob <## "business address: known business #alice"
|
||||
bob <## "use #alice <message> to send messages"
|
||||
bob ##> "/_connect plan 1 @biz.simplex"
|
||||
bob <## "business address: known business #alice"
|
||||
bob <## "use #alice <message> to send messages"
|
||||
registerExpiredName reg bizName (contactAndChannelNameRecord "biz.simplex" (T.pack contactLink) (T.pack channelLink))
|
||||
bob ##> "/_connect plan 1 @biz.simplex"
|
||||
bob <## "business address: known business #alice"
|
||||
bob <## "use #alice <message> to send messages"
|
||||
withCCTransaction bob $ \db -> DB.execute_ db "UPDATE groups SET group_domain_resolved_at = datetime('now', '-2 days')"
|
||||
setGroupNamesStale bob
|
||||
bob ##> "/_connect plan 1 @biz.simplex"
|
||||
bob <## "business address: known business #alice"
|
||||
bob <## "use #alice <message> to send messages"
|
||||
@@ -411,32 +411,29 @@ connectBobByName alice bob = do
|
||||
(bob <## "alice (Alice): contact is connected")
|
||||
(alice <## "bob (Bob): contact is connected")
|
||||
|
||||
testPlanNameReservedCommunity :: HasCallStack => TestParams -> IO ()
|
||||
testPlanNameReservedCommunity = withAliceName $ \reg _l _alice bob -> do
|
||||
registerReservedName reg privacy NRRCommunity
|
||||
bob ##> "/_connect plan 1 @privacy.simplex"
|
||||
bob <## "SimpleX name privacy.simplex: nothing to connect to"
|
||||
bob <## "SimpleX name privacy.simplex is reserved for community"
|
||||
where
|
||||
privacy = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "privacy" [])
|
||||
setContactNamesStale :: TestCC -> IO ()
|
||||
setContactNamesStale cc = withCCTransaction cc $ \db -> DB.execute_ db "UPDATE contact_profiles SET contact_domain_resolved_at = datetime('now', '-2 days')"
|
||||
|
||||
setGroupNamesStale :: TestCC -> IO ()
|
||||
setGroupNamesStale cc = withCCTransaction cc $ \db -> DB.execute_ db "UPDATE groups SET group_domain_resolved_at = datetime('now', '-2 days')"
|
||||
|
||||
testPlanNameReservedOther :: HasCallStack => TestParams -> IO ()
|
||||
testPlanNameReservedOther = withAliceName $ \reg _l _alice bob -> do
|
||||
registerReservedName reg acme NRRTrademark
|
||||
bob ##> "/_connect plan 1 @acme.simplex"
|
||||
registerReservedName reg acmeName NRRTrademark
|
||||
bob ##> "/_connect plan 1 acme.simplex"
|
||||
bob <## "SimpleX name acme.simplex: nothing to connect to"
|
||||
bob <## "SimpleX name acme.simplex is not registered"
|
||||
where
|
||||
acme = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "acme" [])
|
||||
acmeName = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "acme" [])
|
||||
|
||||
testPlanNameNoValidLink :: HasCallStack => TestParams -> IO ()
|
||||
testPlanNameNoValidLink = withAliceName $ \reg _l _alice bob -> do
|
||||
registerName reg boogaloo (emptyRecord "boogaloo.simplex")
|
||||
registerName reg boogalooName (emptyRecord "boogaloo.simplex")
|
||||
bob ##> "/_connect plan 1 @boogaloo.simplex"
|
||||
bob <## "SimpleX name boogaloo.simplex: nothing to connect to"
|
||||
bob <## "SimpleX name boogaloo.simplex has no valid link"
|
||||
where
|
||||
boogaloo = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "boogaloo" [])
|
||||
boogalooName = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "boogaloo" [])
|
||||
|
||||
testPlanKnownNameLive :: HasCallStack => TestParams -> IO ()
|
||||
testPlanKnownNameLive = withAliceName $ \_reg _l alice bob -> do
|
||||
@@ -444,14 +441,6 @@ testPlanKnownNameLive = withAliceName $ \_reg _l alice bob -> do
|
||||
bob ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
knownAlicePlan bob
|
||||
|
||||
testPlanKnownNameExpired :: HasCallStack => TestParams -> IO ()
|
||||
testPlanKnownNameExpired = withAliceName $ \reg shortLink alice bob -> do
|
||||
connectBobByName alice bob
|
||||
registerExpiredName reg aliceSimplexName (contactNameRecord "alice.simplex" shortLink)
|
||||
bob ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
knownAlicePlan bob
|
||||
bob <##. "SimpleX name alice.simplex expired on "
|
||||
|
||||
testPlanKnownNameAvailable :: HasCallStack => TestParams -> IO ()
|
||||
testPlanKnownNameAvailable = withAliceName $ \reg _l alice bob -> do
|
||||
connectBobByName alice bob
|
||||
@@ -464,7 +453,7 @@ testPlanKnownNameReserved :: HasCallStack => TestParams -> IO ()
|
||||
testPlanKnownNameReserved = withAliceName $ \reg _l alice bob -> do
|
||||
connectBobByName alice bob
|
||||
registerName reg aliceSimplexName (emptyRecord "alice.simplex")
|
||||
withCCTransaction bob $ \db -> DB.execute_ db "UPDATE contact_profiles SET contact_domain_resolved_at = datetime('now', '-2 days')"
|
||||
setContactNamesStale bob
|
||||
bob ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
knownAlicePlan bob
|
||||
alice ##> "/_connect plan 1 @alice.simplex"
|
||||
@@ -500,7 +489,7 @@ testPlanKnownNameStale = withAliceName $ \reg shortLink alice bob -> do
|
||||
registerExpiredName reg aliceSimplexName (contactNameRecord "alice.simplex" shortLink)
|
||||
bob ##> "/_connect plan 1 @alice.simplex"
|
||||
knownAlicePlan bob
|
||||
withCCTransaction bob $ \db -> DB.execute_ db "UPDATE contact_profiles SET contact_domain_resolved_at = datetime('now', '-2 days')"
|
||||
setContactNamesStale bob
|
||||
bob ##> "/_connect plan 1 @alice.simplex"
|
||||
knownAlicePlan bob
|
||||
bob <##. "SimpleX name alice.simplex expired on "
|
||||
@@ -522,17 +511,9 @@ testPlanNameResolvedEveryCall = withAliceName $ \reg shortLink _alice bob -> do
|
||||
bob <## "SimpleX name alice.simplex: nothing to connect to"
|
||||
bob <##. "SimpleX name alice.simplex expired on "
|
||||
|
||||
testPlanOwnNameLive :: HasCallStack => TestParams -> IO ()
|
||||
testPlanOwnNameLive = withAliceName $ \_reg _l alice _bob -> do
|
||||
alice ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
alice <## "contact address: own address"
|
||||
|
||||
testPlanOwnNameExpired :: HasCallStack => TestParams -> IO ()
|
||||
testPlanOwnNameExpired = withAliceName $ \reg shortLink alice _bob -> do
|
||||
registerExpiredName reg aliceSimplexName (contactNameRecord "alice.simplex" shortLink)
|
||||
alice ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
alice <## "contact address: own address"
|
||||
alice <##. "your SimpleX name alice.simplex expired on "
|
||||
alice ##> "/c @alice.simplex"
|
||||
alice <## "contact address: own address"
|
||||
alice <##. "your SimpleX name alice.simplex expired on "
|
||||
@@ -574,30 +555,23 @@ testPlanKnownNameAddressChanged ps = withSmpServerAndNames $ \reg ->
|
||||
alice ##> "/_connect plan 1 @alice.simplex"
|
||||
alice <## "contact address: ok to connect, address changed"
|
||||
_ <- getTermLine alice
|
||||
bob ##> "/_connect plan 1 @alice.simplex"
|
||||
knownAlicePlan bob
|
||||
bob ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
bob <## "contact address: ok to connect, address changed"
|
||||
_ <- getTermLine bob
|
||||
withCCTransaction bob $ \db -> DB.execute_ db "UPDATE contact_profiles SET contact_domain_resolved_at = datetime('now', '-2 days')"
|
||||
bob ##> "/_connect plan 1 @alice.simplex"
|
||||
bob <## "contact address: ok to connect, address changed"
|
||||
_ <- getTermLine bob
|
||||
setContactNamesStale bob
|
||||
bob ##> "/c @alice.simplex"
|
||||
bob <## "contact address: ok to connect, address changed"
|
||||
_ <- getTermLine bob
|
||||
bob ##> "/_connect plan 1 @alice.simplex resolve=never"
|
||||
bob ##> "/_connect plan 1 alice.simplex resolve=never"
|
||||
knownAlicePlan bob
|
||||
|
||||
testPlanNameResolverFailed :: HasCallStack => TestParams -> IO ()
|
||||
testPlanNameResolverFailed = withAliceName $ \reg _l _alice bob -> do
|
||||
failNameResolution reg broken
|
||||
bob ##> "/_connect plan 1 @broken.simplex"
|
||||
bob .<## "smpErr = NAME {nameErr = RESOLVER {resolverErr = \"HTTP 500\"}}}"
|
||||
failNameResolution reg brokenName
|
||||
bob ##> "/_connect plan 1 broken.simplex"
|
||||
bob .<## "smpErr = NAME {nameErr = RESOLVER {resolverErr = \"HTTP 500\"}}}"
|
||||
where
|
||||
broken = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "broken" [])
|
||||
brokenName = SimplexNameInfo NTContact (SimplexDomain TLDSimplex "broken" [])
|
||||
|
||||
testPlanKnownNameLinkFailed :: HasCallStack => TestParams -> IO ()
|
||||
testPlanKnownNameLinkFailed ps = withSmpServerAndNames $ \reg ->
|
||||
@@ -607,12 +581,10 @@ testPlanKnownNameLinkFailed ps = withSmpServerAndNames $ \reg ->
|
||||
mapM_ enableNamesRole [alice, bob, cath]
|
||||
_ <- setAliceName reg alice
|
||||
connectBobByName alice bob
|
||||
cath ##> "/ad"
|
||||
(cathLink, _) <- getContactLinks cath True
|
||||
_ <- setAliceName reg cath
|
||||
cath ##> "/da"
|
||||
cath <## "Your chat address is deleted - accepted contacts will remain connected."
|
||||
cath <## "To create a new chat address use /ad"
|
||||
registerName reg aliceSimplexName (contactNameRecord "alice.simplex" (T.pack cathLink))
|
||||
bob ##> "/_connect plan 1 @alice.simplex resolve=all"
|
||||
knownAlicePlan bob
|
||||
|
||||
@@ -622,28 +594,16 @@ testPlanChannelNameMoved ps = withSmpServerAndNames $ \reg ->
|
||||
withNewTestChatOpts ps relayTestOpts "cath" cathProfile $ \cath ->
|
||||
withNewTestChat ps "bob" bobProfile $ \bob -> do
|
||||
mapM_ enableNamesRole [alice, cath, bob]
|
||||
(shortLink, _) <- prepareChannel1Relay "team" alice cath
|
||||
(shortLink, fullLink) <- prepareChannel1Relay "team" alice cath
|
||||
registerName reg teamName (channelNameRecord "team.simplex" (T.pack shortLink))
|
||||
alice ##> "/public group access #team domain=team.simplex"
|
||||
alice <## "updated public group access: domain=team.simplex"
|
||||
cath <## "alice updated group #team: (signed)"
|
||||
cath <## "updated public group access: domain=team.simplex"
|
||||
bob ##> "/c #team.simplex"
|
||||
bob <## "#team: connection started"
|
||||
concurrentlyN_
|
||||
[ bob
|
||||
<### [ "#team: joining the group (connecting to relay cath)...",
|
||||
"#team: you joined the group (connected to relay cath)"
|
||||
]
|
||||
, do
|
||||
cath <## "bob (Bob): accepting request to join group #team..."
|
||||
cath <## "#team: bob joined the group"
|
||||
, alice <### [EndsWith "introduced bob (Bob) in the channel"]
|
||||
]
|
||||
memberJoinChannel "team" [cath] [alice] shortLink fullLink bob
|
||||
bob ##> "/_verify domain #1"
|
||||
bob <## "SimpleX name #team verified"
|
||||
registerExpiredName reg teamName (channelNameRecord "team.simplex" (T.pack shortLink))
|
||||
alice ##> "/_connect plan 1 #team.simplex"
|
||||
alice <## "group link: own link for group #team"
|
||||
alice <##. "your SimpleX name team.simplex expired on "
|
||||
alice ##> "/c #team.simplex"
|
||||
alice <## "group link: own link for group #team"
|
||||
alice <##. "your SimpleX name team.simplex expired on "
|
||||
@@ -660,11 +620,6 @@ testPlanChannelNameMoved ps = withSmpServerAndNames $ \reg ->
|
||||
where
|
||||
teamName = SimplexNameInfo NTPublicGroup (SimplexDomain TLDSimplex "team" [])
|
||||
|
||||
nameWarningTests :: SpecWith TestParams
|
||||
nameWarningTests = do
|
||||
it "warning for a name with no local chat" $ \_ -> testNameLinkOrWarning
|
||||
it "warning for own name" $ \_ -> testOwnNameWarning
|
||||
|
||||
testNameLinkOrWarning :: IO ()
|
||||
testNameLinkOrWarning = do
|
||||
linkOrWarning NTContact (registered Nothing Nothing contactRecord) `shouldBe` Right contactLink
|
||||
|
||||
@@ -76,7 +76,6 @@ registerExpiredName reg ni nameRecord = do
|
||||
registerReservedName :: NameRegistry -> SimplexNameInfo -> NameReservedReason -> IO ()
|
||||
registerReservedName reg ni reservedReason = registerRegistration reg ni NRReserved {reservedReason}
|
||||
|
||||
|
||||
failNameResolution :: NameRegistry -> SimplexNameInfo -> IO ()
|
||||
failNameResolution reg ni = atomically $ modifyTVar' reg $ M.insert (registryKey ni) AnswerFails
|
||||
|
||||
|
||||
Reference in new issue
Block a user