diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/Note.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/Note.kt index 98e327fe4..4edd15882 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/Note.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/Note.kt @@ -90,8 +90,7 @@ class AddressableNote( override fun address() = address override fun createdAt(): Long? { - val currentEvent = event - if (currentEvent == null) return null + val currentEvent = event ?: return null if (currentEvent is PublishedAtProvider) return currentEvent.publishedAt() ?: currentEvent.createdAt return currentEvent.createdAt } @@ -204,7 +203,7 @@ open class Note( is IsInPublicChatChannel -> { inGatherers?.forEach { - if (it is com.vitorpamplona.amethyst.commons.model.Channel) { + if (it is Channel) { it.relays().firstOrNull()?.let { return it } } } @@ -216,7 +215,7 @@ open class Note( is LiveActivitiesChatMessageEvent -> { inGatherers?.forEach { - if (it is com.vitorpamplona.amethyst.commons.model.Channel) { + if (it is Channel) { it.relays().firstOrNull()?.let { return it } } } @@ -230,14 +229,14 @@ open class Note( val currentOutbox = author?.outboxRelays()?.toSet() return if (relays.isNotEmpty()) { - if (currentOutbox != null && currentOutbox.isNotEmpty()) { + if (!currentOutbox.isNullOrEmpty()) { val relayMatchesOutbox = relays.firstOrNull { it in currentOutbox } if (relayMatchesOutbox != null) { return relayMatchesOutbox } } - return relays.firstOrNull() + relays.firstOrNull() } else { currentOutbox?.firstOrNull() ?: author?.mostUsedNonLocalRelay() } @@ -313,14 +312,14 @@ open class Note( zapPayments.keys + zapPayments.values.filterNotNull() - replies = listOf() - reactions = mapOf>() - boosts = listOf() - reports = mapOf>() - zaps = mapOf() - zapPayments = mapOf() + replies = listOf() + reactions = mapOf() + boosts = listOf() + reports = mapOf() + zaps = mapOf() + zapPayments = mapOf() zapsAmount = BigDecimal.ZERO - relays = listOf() + relays = listOf() if (repliesChanged) flowSet?.replies?.invalidateData() if (reactionsChanged) flowSet?.reactions?.invalidateData() @@ -990,11 +989,11 @@ class NoteState( fun List.eventIdSet() = mapNotNullTo(mutableSetOf()) { it.event?.id } -fun Array.events() = mapNotNull { it.note.event as? T } +inline fun Array.events() = mapNotNull { it.note.event as? T } -fun List.events() = mapNotNull { it.event as? T } +inline fun List.events() = mapNotNull { it.event as? T } -fun List.updateFlow(): Flow> = +inline fun List.updateFlow(): Flow> = if (this.isEmpty()) { MutableStateFlow(emptyList()) } else { @@ -1005,7 +1004,7 @@ fun List.updateFlow(): Flow> = } } -public inline fun Iterable.anyEvent(predicate: (T) -> Boolean): Boolean { +inline fun Iterable.anyEvent(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return false for (note in this) { val noteEvent = note.event as? T @@ -1014,7 +1013,7 @@ public inline fun Iterable.anyEvent(predicate: (T) -> Boolean): Boolea return false } -public inline fun Iterable.filterEvents(predicate: (T) -> Boolean): List { +inline fun Iterable.filterEvents(predicate: (T) -> Boolean): List { if (this is Collection && isEmpty()) return emptyList() val dest = ArrayList() @@ -1027,7 +1026,7 @@ public inline fun Iterable.filterEvents(predicate: (T) -> Boolean): Li return dest } -public fun Iterable.filterAuthoredEvents(pubkey: HexKey): List { +inline fun Iterable.filterAuthoredEvents(pubkey: HexKey): List { if (this is Collection && isEmpty()) return emptyList() val dest = ArrayList() @@ -1042,7 +1041,7 @@ public fun Iterable.filterAuthoredEvents(pubkey: HexKey): List { return dest } -public inline fun Iterable.anyNotNullEvent(predicate: (Event) -> Boolean): Boolean { +inline fun Iterable.anyNotNullEvent(predicate: (Event) -> Boolean): Boolean { if (this is Collection && isEmpty()) return false for (note in this) { val noteEvent = note.event @@ -1051,7 +1050,7 @@ public inline fun Iterable.anyNotNullEvent(predicate: (Event) -> Boolean): return false } -fun List.latestByAuthor(): Map { +inline fun List.latestByAuthor(): Map { val oneResponsePerUser = mutableMapOf() forEach { note ->