Get rid of the crash

This commit is contained in:
Kgothatso Ngako
2026-05-02 01:48:33 +02:00
parent b9cece869e
commit 54b212ea7d
12 changed files with 28 additions and 48 deletions

View File

@@ -17,36 +17,36 @@ import kotlinx.coroutines.flow.Flow
@Dao
interface NostrEventDao {
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY createdAt DESC")
fun observeNostrEvents(kinds: Array<Kind>): Flow<List<LocalNostrEvent?>?>
fun observeNostrEvents(kinds: Array<Kind>): Flow<List<LocalNostrEvent>?>
@Query("SELECT * FROM NostrEvent WHERE content LIKE '%' || :search || '%' AND kind in (:kinds) ORDER BY createdAt DESC")
fun observeFilteredNostrEvents(
kinds: Array<Kind>,
search: String
): Flow<List<LocalNostrEvent?>?>
): Flow<List<LocalNostrEvent>?>
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND id in (:ids) ORDER BY createdAt DESC")
fun observeFilteredNostrEvents(
kinds: Array<Kind>,
ids: Array<HexKey>,
): Flow<List<LocalNostrEvent?>?>
): Flow<List<LocalNostrEvent>?>
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND pubKey in (:authors) ORDER BY createdAt DESC LIMIT 50")
fun observeAuthoredNostrEvents(
kinds: Array<Kind>,
authors: Array<HexKey>,
): Flow<List<LocalNostrEvent?>?>
): Flow<List<LocalNostrEvent>?>
@Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :publicKey || '%' AND kind in (:kinds) ORDER BY createdAt DESC")
fun observePublicKeyMentionedNostrEvents(
kinds: Array<Kind>,
publicKey: HexKey
): Flow<List<LocalNostrEvent?>?>
): Flow<List<LocalNostrEvent>?>
@RawQuery
fun observePublicKeyFollowingNostrEvents(
query: RoomRawQuery
): Flow<List<LocalNostrEvent?>?>
): Flow<List<LocalNostrEvent>?>
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY savedAt DESC")
fun getAllNostrEvents(kinds: Array<Kind>): List<NostrEvent>

View File

@@ -38,12 +38,6 @@ data class LocalInReplyToNostrEvent(
)
val profile: Profile?,
@Relation(
entity = Mention::class,
parentColumn = "inReplyToNostrEventId",
entityColumn = "mentioningNostrEventId",
)
val mentionedProfiles: List<LocalMention?> = emptyList(),
) {
@Composable
fun RenderNotePreview() {

View File

@@ -6,7 +6,7 @@ import androidx.room3.Embedded
import androidx.room3.Relation
data class LocalMention(
@Embedded val mention: Mention?,
@Embedded val mention: Mention,
@Relation(
parentColumn = "mentionedPublicKey",

View File

@@ -56,12 +56,11 @@ data class LocalNostrEvent(
)
val localInReplyToNostrEvent: LocalInReplyToNostrEvent? = null,
@Relation(
entity = Mention::class,
parentColumn = "id",
entityColumn = "mentioningNostrEventId",
)
val mentionedProfiles: List<LocalMention?>? = emptyList(),
// @Relation(
// parentColumn = "id",
// entityColumn = "mentioningNostrEventId",
// )
// val mentionedProfiles: List<Mention>? = emptyList(),
) {
@Composable
fun RenderNotePreview() {

View File

@@ -37,13 +37,6 @@ data class LocalQuotedNostrEvent(
entityColumn = "publicKey"
)
val profile: Profile?,
@Relation(
entity = Mention::class,
parentColumn = "quotedNostrEventId",
entityColumn = "mentioningNostrEventId",
)
val mentionedProfiles: List<LocalMention?> = emptyList(),
) {
@Composable
fun RenderNotePreview() {
@@ -85,7 +78,6 @@ data class LocalQuotedNostrEvent(
RichContent(
nostrEvent = nostrEvent,
localQuotedNostrEvent = null,
mentionedProfiles = mentionedProfiles,
)
}

View File

@@ -43,7 +43,7 @@ data class LocalRepostedNostrEvent(
parentColumn = "repostedNostrEventId",
entityColumn = "mentioningNostrEventId",
)
val mentionedProfiles: List<LocalMention?> = emptyList(),
val mentionedProfiles: List<LocalMention>? = emptyList(),
) {
@Composable
fun RenderNotePreview() {

View File

@@ -441,7 +441,7 @@ class DatabaseNostrRepository(
)
}
override suspend fun observeNostrFeed(): Flow<List<LocalNostrEvent?>?> {
override suspend fun observeNostrFeed(): Flow<List<LocalNostrEvent>?> {
return database.nostrEventDao().observeNostrEvents(
kinds = arrayOf(
TextNoteEvent.KIND,
@@ -452,7 +452,7 @@ class DatabaseNostrRepository(
)
}
override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent?>?> {
override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent>?> {
return when {
synchronizationFilter.kinds != null && synchronizationFilter.search != null -> {

View File

@@ -84,9 +84,9 @@ interface NostrRepository {
suspend fun getNostrEvent(publicKey: HexKey, kind: Kind): NostrEvent?
suspend fun observeNostrFeed(): Flow<List<LocalNostrEvent?>?>
suspend fun observeNostrFeed(): Flow<List<LocalNostrEvent>?>
suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent?>?>
suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent>?>
suspend fun observeLocalNostrEventById(nostrEventId: String): Flow<LocalNostrEvent?>
@@ -207,11 +207,11 @@ interface NostrRepository {
TODO("Not yet implemented")
}
override suspend fun observeNostrFeed(): Flow<List<LocalNostrEvent?>?> {
override suspend fun observeNostrFeed(): Flow<List<LocalNostrEvent>?> {
TODO("Not yet implemented")
}
override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent?>?> {
override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow<List<LocalNostrEvent>?> {
TODO("Not yet implemented")
}

View File

@@ -35,7 +35,6 @@ import coil3.compose.AsyncImage
fun RichContent(
nostrEvent: NostrEvent,
localQuotedNostrEvent: LocalQuotedNostrEvent?,
mentionedProfiles: List<LocalMention?>?,
style: TextStyle = MaterialTheme.typography.bodyLarge,
color: Color = MaterialTheme.colorScheme.onSurface,
linkColor: Color = Color.Unspecified,
@@ -110,14 +109,15 @@ fun RichContent(
val profileNames = remember(profilePubkeys) {
val names = mutableMapOf<String, String>()
if (mentionedProfiles?.isNotEmpty() == true) {
Logger.withTag("RichContent").d("mentionedProfiles: ${mentionedProfiles}")
for (pubkey in profilePubkeys) {
val mentionedProfile = mentionedProfiles.find { mentionedProfile -> mentionedProfile?.profile?.publicKey == pubkey }
names[pubkey] = mentionedProfile?.profile?.humanReadableNameOrPubkey()
?: "${pubkey.take(8)}...${pubkey.takeLast(4)}"
}
}
// TODO: Get profiles from profilePubkeys
// if (mentionedProfiles?.isNotEmpty() == true) {
// Logger.withTag("RichContent").d("mentionedProfiles: ${mentionedProfiles}")
// for (pubkey in profilePubkeys) {
// val mentionedProfile = mentionedProfiles.find { mentionedProfile -> mentionedProfile?.profile?.publicKey == pubkey }
// names[pubkey] = mentionedProfile?.profile?.humanReadableNameOrPubkey()
// ?: "${pubkey.take(8)}...${pubkey.takeLast(4)}"
// }
// }
names
}

View File

@@ -143,7 +143,6 @@ fun TextNoteEventDetail(
),
nostrEvent = localNostrEvent.nostrEvent,
localQuotedNostrEvent = localNostrEvent.localQuotedNostrEvent,
mentionedProfiles = localNostrEvent.mentionedProfiles
)
Row(

View File

@@ -68,7 +68,6 @@ fun LocalNostrEvent.ListView(
profile = localRepostedNostrEvent.profile,
localQuotedNostrEvent = null,
localInReplyToNostrEvent = null,
mentionedProfiles = localRepostedNostrEvent.mentionedProfiles,
onNavigateToEvent = onNavigateToEvent
)
} else {
@@ -104,7 +103,6 @@ fun LocalNostrEvent.ListView(
profile = profile,
localQuotedNostrEvent = localQuotedNostrEvent,
localInReplyToNostrEvent = localInReplyToNostrEvent,
mentionedProfiles = mentionedProfiles,
onNavigateToEvent = onNavigateToEvent
)
}

View File

@@ -36,7 +36,6 @@ internal fun TextNoteFeedItem(
profile: Profile?,
localInReplyToNostrEvent: LocalInReplyToNostrEvent?,
localQuotedNostrEvent: LocalQuotedNostrEvent?,
mentionedProfiles: List<LocalMention?>?,
onNavigateToEvent: (HexKey) -> Unit
) {
if (localInReplyToNostrEvent != null) {
@@ -108,7 +107,6 @@ internal fun TextNoteFeedItem(
modifier = Modifier.fillMaxWidth(),
nostrEvent = nostrEvent,
localQuotedNostrEvent = localQuotedNostrEvent,
mentionedProfiles = mentionedProfiles
)
LazyRow(