Skip to content

Commit 1e38929

Browse files
ben-kaufmanclaude
andcommitted
fix: delete contacts on profile deletion
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2051774 commit 1e38929

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

app/src/main/java/to/bitkit/repositories/PubkyRepo.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,31 @@ class PubkyRepo @Inject constructor(
401401
val session = requireNotNull(keychain.loadString(Keychain.Key.PAYKIT_SESSION.name)) {
402402
"No session available"
403403
}
404+
deleteAllContacts(session)
404405
pubkyService.sessionDelete(session, Env.profilePath)
405406
}
406407
signOut().getOrThrow()
407408
}
408409

410+
private suspend fun deleteAllContacts(session: String) {
411+
val contactPaths = runCatching {
412+
pubkyService.sessionList(session, Env.contactsBasePath)
413+
}.getOrElse {
414+
if (it.isMissingPubkyDirectory()) return
415+
throw it
416+
}
417+
contactPaths.forEach { path ->
418+
val contactKey = path.substringAfterLast("/")
419+
runCatching {
420+
pubkyService.sessionDelete(session, "${Env.contactsBasePath}$contactKey")
421+
}.onFailure {
422+
Logger.warn("Failed to delete contact '$contactKey'", it, context = TAG)
423+
}
424+
}
425+
_contacts.update { emptyList() }
426+
Logger.info("Deleted all contacts", context = TAG)
427+
}
428+
409429
@Suppress("LongParameterList")
410430
private suspend fun writeProfile(
411431
sessionSecret: String,

0 commit comments

Comments
 (0)