Bug fix on profile crash

This commit is contained in:
Kgothatso Ngako
2026-04-20 00:20:56 +02:00
parent 9358aa07a8
commit 033c99cf9e
6 changed files with 23 additions and 11 deletions

View File

@@ -115,6 +115,7 @@ abstract class NostrDao(
if (profile == null) {
val placeHolderProfile = Profile(
publicKey = nostrEvent.pubKey,
createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync,
)
database.profileDao().insertPlaceholderProfile(placeHolderProfile)
@@ -134,6 +135,8 @@ abstract class NostrDao(
}
)
}
} else {
logger.w("We somehow have an unsignedNostrEvent: $nostrEvent")
}
// Sync tagged events and authors...
@@ -223,9 +226,11 @@ abstract class NostrDao(
if (replyingToPost == null) {
// Persist PlaceHolder and sync
// TODO: Get replyingToAuthorPublicKey
database.postDao().insert(
Post(
id = post.replyToId,
createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync handled by tagged events...
content = post.replyToId,
profilePublicKey = nostrEvent.pubKey // Will get overwriting by sync handled by tagged events...
@@ -245,6 +250,7 @@ abstract class NostrDao(
database.postDao().insert(
Post(
id = reaction.replyToId,
createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync handled by tagged events...
content = reaction.replyToId,
profilePublicKey = nostrEvent.pubKey // Will get overwriting by sync handled by tagged events...
@@ -263,6 +269,7 @@ abstract class NostrDao(
database.postDao().insert(
Post(
id = repost.repostedPostId,
createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync handled by tagged events...
content = repost.repostedPostId,
profilePublicKey = nostrEvent.pubKey // Will get overwriting by sync handled by tagged events...
@@ -277,6 +284,7 @@ abstract class NostrDao(
database.profileDao().insertPlaceholderProfile(
Profile(
publicKey = nostrEvent.pubKey,
createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync handled by tagged events...
)
)
@@ -308,6 +316,7 @@ abstract class NostrDao(
database.postDao().insert(
Post(
id = zap.postId,
createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync,
content = zap.postId,
profilePublicKey = nostrEvent.pubKey // Will get overwriting by sync,

View File

@@ -14,7 +14,7 @@ data class LocalNostrEvent(
parentColumn = "pubKey",
entityColumn = "publicKey"
)
val profile: Profile,
val profile: Profile?,
@Relation(
parentColumn = "id",

View File

@@ -90,11 +90,11 @@ fun MetadataEventDetail(
verticalArrangement = Arrangement.Center
) {
Text(
text = profile.displayName ?: profile.userName ?: profile.publicKey,
text = profile?.displayName ?: profile?.userName ?: localNostrEvent.nostrEvent.pubKey,
style = MaterialTheme.typography.titleLarge
)
profile.nip05?.let {
profile?.nip05?.let {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp)
@@ -141,7 +141,7 @@ fun MetadataEventDetail(
Icon(
Icons.Default.Person,
modifier = Modifier.size(50.dp),
contentDescription = profile.displayName ?: profile.userName ?: "Profile picture"
contentDescription = profile?.displayName ?: profile?.userName ?: "Profile picture"
)
@@ -164,8 +164,10 @@ fun MetadataEventDetail(
modifier = Modifier.fillMaxWidth().padding(
horizontal = 20.dp
),
maxLines = 2,
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Start,
text = profile.about ?: ""
text = profile?.about ?: ""
)
}
}

View File

@@ -94,18 +94,18 @@ fun TextNoteEventDetail(
Icon(
Icons.Default.Person,
modifier = Modifier.size(50.dp),
contentDescription = profile.displayName ?: profile.userName ?: "Profile picture"
contentDescription = profile?.displayName ?: profile?.userName ?: "Profile picture"
)
Column(
modifier = Modifier.weight(1f)
) {
Text(
text = profile.displayName ?: profile.userName ?: profile.publicKey,
text = profile?.displayName ?: profile?.userName ?: localNostrEvent.nostrEvent.pubKey,
style = MaterialTheme.typography.bodyLarge
)
profile.nip05?.let {
profile?.nip05?.let {
Text(
text = profile.nip05 ?: "",
style = MaterialTheme.typography.labelMedium

View File

@@ -52,13 +52,14 @@ fun LocalNostrEvent.ListView(
modifier = Modifier.fillMaxWidth().clickable(
enabled = true,
onClick = {
onNavigateToEvent.invoke(profile.nostrEventId)
onNavigateToEvent.invoke(profile?.nostrEventId ?: nostrEvent.id)
// TODO: Show error
}
)
) {
Text(
modifier = Modifier.weight(1f),
text = profile.displayName ?: profile.userName ?: profile.publicKey,
text = profile?.displayName ?: profile?.userName ?: nostrEvent.pubKey,
style = MaterialTheme.typography.labelSmall
)
Text(

View File

@@ -192,7 +192,7 @@ class NavigationViewModel(
)
}
else -> {
logger.d("Unhandled message: $nostrIncomingMessage")
logger.d("Unhandled message ${synchronizeNostrEventRequest.relayURL}: $nostrIncomingMessage")
}
}
}