mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-06 18:38:34 +00:00
fixes EP review
This commit is contained in:
@@ -5252,9 +5252,6 @@ enum class SimplexTLD {
|
||||
@SerialName("web") web
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class SimplexNameResolved(val at: Long, val expires: Long? = null)
|
||||
|
||||
@Serializable
|
||||
sealed class NameRegistration {
|
||||
// held by someone; expires/graceUntil are absent from an older router, which means "not known", not "live forever"
|
||||
|
||||
-2
@@ -123,7 +123,6 @@ class AppPreferences {
|
||||
val privacyAcceptImages = mkBoolPreference(SHARED_PREFS_PRIVACY_ACCEPT_IMAGES, true)
|
||||
val privacyLinkPreviews = mkBoolPreference(SHARED_PREFS_PRIVACY_LINK_PREVIEWS, true)
|
||||
val privacyVerifySimplexNames = mkBoolPreference(SHARED_PREFS_PRIVACY_VERIFY_SIMPLEX_NAMES, false)
|
||||
val simplexNamesResolvedAt = mkStrPreference(SHARED_PREFS_SIMPLEX_NAMES_RESOLVED_AT, null)
|
||||
val privacyLinkPreviewsShowAlert = mkBoolPreference(SHARED_PREFS_PRIVACY_LINK_PREVIEWS_SHOW_ALERT, true)
|
||||
val privacySanitizeLinks = mkBoolPreference(SHARED_PREFS_PRIVACY_SANITIZE_LINKS, false)
|
||||
// TODO remove
|
||||
@@ -412,7 +411,6 @@ class AppPreferences {
|
||||
private const val SHARED_PREFS_PRIVACY_TRANSFER_IMAGES_INLINE = "PrivacyTransferImagesInline"
|
||||
private const val SHARED_PREFS_PRIVACY_LINK_PREVIEWS = "PrivacyLinkPreviews"
|
||||
private const val SHARED_PREFS_PRIVACY_VERIFY_SIMPLEX_NAMES = "PrivacyVerifySimplexNames"
|
||||
private const val SHARED_PREFS_SIMPLEX_NAMES_RESOLVED_AT = "SimplexNamesResolvedAt"
|
||||
private const val SHARED_PREFS_PRIVACY_LINK_PREVIEWS_SHOW_ALERT = "PrivacyLinkPreviewsShowAlert"
|
||||
private const val SHARED_PREFS_PRIVACY_SANITIZE_LINKS = "PrivacySanitizeLinks"
|
||||
private const val SHARED_PREFS_PRIVACY_CHAT_LIST_OPEN_LINKS = "ChatListOpenLinks" // TODO remove
|
||||
|
||||
+1
-51
@@ -22,7 +22,6 @@ import chat.simplex.common.views.usersettings.simplexTeamUri
|
||||
import chat.simplex.res.MR
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.datetime.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
enum class ConnectionLinkType {
|
||||
INVITATION, CONTACT, GROUP
|
||||
@@ -73,46 +72,8 @@ private fun openNameHowTo(uriHandler: UriHandler) = openBrowserAlert(SIMPLEX_NAM
|
||||
|
||||
private const val SIMPLEX_NAMES_HOWTO_URL = "https://simplex.domains/#testing"
|
||||
|
||||
private const val NAME_RESOLVED_DAY_SECONDS = 24 * 60 * 60L
|
||||
|
||||
private fun nowSeconds(): Long = Clock.System.now().epochSeconds
|
||||
|
||||
private fun loadNamesResolvedAt(): MutableMap<String, SimplexNameResolved> =
|
||||
try {
|
||||
val s = ChatController.appPrefs.simplexNamesResolvedAt.get() ?: return mutableMapOf()
|
||||
json.decodeFromString<Map<String, SimplexNameResolved>>(s).toMutableMap()
|
||||
} catch (e: Exception) {
|
||||
mutableMapOf()
|
||||
}
|
||||
|
||||
private fun saveNamesResolvedAt(m: Map<String, SimplexNameResolved>) {
|
||||
val now = nowSeconds()
|
||||
val kept = m.filterValues { now - it.at < 7 * NAME_RESOLVED_DAY_SECONDS }
|
||||
try {
|
||||
ChatController.appPrefs.simplexNamesResolvedAt.set(json.encodeToString<Map<String, SimplexNameResolved>>(kept))
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "saveNamesResolvedAt: ${e.stackTraceToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun simplexNameResolvedRecently(domain: SimplexDomain): Boolean {
|
||||
val r = loadNamesResolvedAt()[domain.fullDomainName] ?: return false
|
||||
val now = nowSeconds()
|
||||
if (now - r.at >= NAME_RESOLVED_DAY_SECONDS) return false
|
||||
return r.expires == null || now < r.expires
|
||||
}
|
||||
|
||||
fun recordSimplexNameResolved(domain: SimplexDomain, reg: NameRegistration?) {
|
||||
val m = loadNamesResolvedAt()
|
||||
m[domain.fullDomainName] = SimplexNameResolved(nowSeconds(), (reg as? NameRegistration.Registered)?.expires)
|
||||
saveNamesResolvedAt(m)
|
||||
}
|
||||
|
||||
fun clearSimplexNameResolved(fullDomainName: String) {
|
||||
val m = loadNamesResolvedAt()
|
||||
if (m.remove(fullDomainName) != null) saveNamesResolvedAt(m)
|
||||
}
|
||||
|
||||
private fun showNameRegistrationAlert(
|
||||
rhId: Long?,
|
||||
domain: SimplexDomain,
|
||||
@@ -230,18 +191,7 @@ private suspend fun planAndConnectTask(
|
||||
cleanup?.invoke()
|
||||
completable.complete(!completable.isActive)
|
||||
}
|
||||
val nameTarget = (strConnectTarget(shortOrFullLink.trim()) as? ConnectTarget.Name)?.nameInfo
|
||||
val freshName = nameTarget != null && simplexNameResolvedRecently(nameTarget.nameDomain)
|
||||
var result = if (freshName) {
|
||||
chatModel.controller.apiConnectPlan(rhId, shortOrFullLink, PlanResolveMode.PRMNever, linkOwnerSig, mutableStateOf(false))
|
||||
} else null
|
||||
if (result == null && inProgress.value) {
|
||||
val mode = if (nameTarget != null) PlanResolveMode.PRMAll else PlanResolveMode.PRMUnknown
|
||||
result = chatModel.controller.apiConnectPlan(rhId, shortOrFullLink, mode, linkOwnerSig, inProgress)
|
||||
if (nameTarget != null && result != null) {
|
||||
recordSimplexNameResolved(nameTarget.nameDomain, result.connectionPlan.nameRegistration())
|
||||
}
|
||||
}
|
||||
val result = chatModel.controller.apiConnectPlan(rhId, shortOrFullLink, linkOwnerSig = linkOwnerSig, inProgress = inProgress)
|
||||
connectProgressManager.stopConnectProgress()
|
||||
if (!inProgress.value) { return completable }
|
||||
if (result != null) {
|
||||
|
||||
-1
@@ -388,7 +388,6 @@ private fun UserAddressLayout(
|
||||
save = { simplexDomain ->
|
||||
try {
|
||||
val u = chatModel.controller.apiSetUserDomain(user?.remoteHostId, simplexDomain)
|
||||
domain?.let { clearSimplexNameResolved(it) }
|
||||
withContext(Dispatchers.Main) { chatModel.updateUser(u) }
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user