From 6d69e15d7ea317053e8dea7951d969ec4b197e83 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Thu, 25 Jun 2026 14:00:23 +0700 Subject: [PATCH] add prune database function --- shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt | 10 +++++++++- .../commonMain/kotlin/su/reya/coop/NostrViewModel.kt | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt index 0ef6116..ca2ce5f 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt @@ -188,6 +188,14 @@ class Nostr { } } + suspend fun prune() { + try { + client?.database()?.wipe() + } catch (e: Exception) { + throw IllegalStateException("Failed to prune database: ${e.message}", e) + } + } + suspend fun setSigner(new: AsyncNostrSigner) { try { signer.switch(new) @@ -994,7 +1002,7 @@ class Nostr { try { val currentUser = signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in") - + val kind = Kind.fromStd(KindStandard.CONTACT_LIST) val filter = Filter().kind(kind).author(currentUser).limit(1u) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index 052c5d9..dd1aced 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -325,8 +325,11 @@ class NostrViewModel( fun logout() { viewModelScope.launch { - secretStore.clear("user_signer") + // Reset the nostr state and wipe database nostr.signer.switch(Keys.generate()) + nostr.prune() + // Clear credential + secretStore.clear("user_signer") _signerRequired.value = true } } @@ -821,7 +824,7 @@ class NostrViewModel( } return emptyList() } - + suspend fun verifyActivity(pubkey: PublicKey): Timestamp? { return try { nostr.verifyActivity(pubkey)