update home screen

This commit is contained in:
2026-05-06 08:39:19 +07:00
parent 109fe28d48
commit 06252ecbb4
9 changed files with 227 additions and 104 deletions

View File

@@ -39,6 +39,8 @@ class Nostr {
private set
var deviceSigner: NostrSigner? = null
private set
var userPubkey: PublicKey? = null
private set
var contactList: List<PublicKey> = emptyList()
private set
@@ -82,13 +84,23 @@ class Nostr {
}
suspend fun setKeySigner(keys: Keys) {
signer = NostrSigner.keys(keys)
getUserMetadata()
try {
signer = NostrSigner.keys(keys)
userPubkey = signer?.getPublicKey()
getUserMetadata()
} catch (e: Exception) {
println("Failed to set signer: ${e.message}")
}
}
suspend fun setRemoteSigner(remote: NostrConnect) {
signer = NostrSigner.nostrConnect(remote)
getUserMetadata()
try {
signer = NostrSigner.nostrConnect(remote)
userPubkey = signer?.getPublicKey()
getUserMetadata()
} catch (e: Exception) {
println("Failed to set remote signer: ${e.message}")
}
}
suspend fun isSignedByUser(event: Event): Boolean {

View File

@@ -90,6 +90,14 @@ class NostrViewModel(
_metadataStore.getOrPut(pubkey) { MutableStateFlow(null) }.value = metadata
}
fun getUserProfile(): StateFlow<Metadata?> {
return try {
getMetadata(nostr.userPubkey!!)
} catch (e: Exception) {
MutableStateFlow(null)
}
}
fun initAndConnect(dbPath: String) {
viewModelScope.launch {
try {
@@ -175,10 +183,11 @@ class NostrViewModel(
}
}
fun import(secret: String) {
fun importIdentity(secret: String) {
// TODO: Implement import
}
fun getChatRooms() {
viewModelScope.launch {
try {