Fixes unnecessary typecasting from long to int in created ats

This commit is contained in:
Vitor Pamplona
2025-09-12 15:08:10 -04:00
parent 46fec1d480
commit 47d201f936
14 changed files with 41 additions and 41 deletions
@@ -96,7 +96,7 @@ abstract class Channel : NotesGatherer {
notes.put(note.idHex, note) notes.put(note.idHex, note)
note.addGatherer(this) note.addGatherer(this)
if ((note.createdAt() ?: 0) > (lastNote?.createdAt() ?: 0)) { if ((note.createdAt() ?: 0L) > (lastNote?.createdAt() ?: 0L)) {
lastNote = note lastNote = note
} }
@@ -700,7 +700,7 @@ object LocalCache : ILocalCache {
if (isVerified || justVerify(event)) { if (isVerified || justVerify(event)) {
val replyTo = computeReplyTo(event) val replyTo = computeReplyTo(event)
if (event.createdAt > (note.createdAt() ?: 0)) { if (event.createdAt > (note.createdAt() ?: 0L)) {
note.loadEvent(event, author, replyTo) note.loadEvent(event, author, replyTo)
refreshNewNoteObservers(note) refreshNewNoteObservers(note)
@@ -743,7 +743,7 @@ object LocalCache : ILocalCache {
} }
if (isVerified || justVerify(event)) { if (isVerified || justVerify(event)) {
if (event.createdAt > (note.createdAt() ?: 0)) { if (event.createdAt > (note.createdAt() ?: 0L)) {
val replyTo = computeReplyTo(event) val replyTo = computeReplyTo(event)
note.loadEvent(event, author, replyTo) note.loadEvent(event, author, replyTo)
@@ -845,7 +845,7 @@ object LocalCache : ILocalCache {
if (note.event?.id == event.id) return false if (note.event?.id == event.id) return false
if (event.createdAt > (note.createdAt() ?: 0) && (isVerified || justVerify(event))) { if (event.createdAt > (note.createdAt() ?: 0L) && (isVerified || justVerify(event))) {
note.loadEvent(event, author, emptyList()) note.loadEvent(event, author, emptyList())
val channel = getOrCreateLiveChannel(note.address) val channel = getOrCreateLiveChannel(note.address)
@@ -1073,7 +1073,7 @@ object LocalCache : ILocalCache {
// Already processed this event. // Already processed this event.
if (note.event?.id == event.id) return false if (note.event?.id == event.id) return false
if (event.createdAt > (note.createdAt() ?: 0) && (isVerified || justVerify(event))) { if (event.createdAt > (note.createdAt() ?: 0L) && (isVerified || justVerify(event))) {
note.loadEvent(event, author, emptyList()) note.loadEvent(event, author, emptyList())
author.flowSet?.statuses?.invalidateData() author.flowSet?.statuses?.invalidateData()
@@ -1196,7 +1196,7 @@ object LocalCache : ILocalCache {
// Already processed this event. // Already processed this event.
if (replaceableNote.event?.id == event.id) return isVerified if (replaceableNote.event?.id == event.id) return isVerified
if (event.createdAt > (replaceableNote.createdAt() ?: 0) && (isVerified || justVerify(event))) { if (event.createdAt > (replaceableNote.createdAt() ?: 0L) && (isVerified || justVerify(event))) {
// clear index from previous tags // clear index from previous tags
replaceableNote.replyTo?.forEach { replaceableNote.replyTo?.forEach {
it.removeNote(replaceableNote) it.removeNote(replaceableNote)
@@ -1257,7 +1257,7 @@ object LocalCache : ILocalCache {
val deleteNoteEvent = deleteNote.event val deleteNoteEvent = deleteNote.event
if (deleteNoteEvent is AddressableEvent) { if (deleteNoteEvent is AddressableEvent) {
val addressableNote = getAddressableNoteIfExists(deleteNoteEvent.addressTag()) val addressableNote = getAddressableNoteIfExists(deleteNoteEvent.addressTag())
if (addressableNote?.author?.pubkeyHex == event.pubKey && (addressableNote.createdAt() ?: 0) <= event.createdAt) { if (addressableNote?.author?.pubkeyHex == event.pubKey && (addressableNote.createdAt() ?: 0L) <= event.createdAt) {
// Counts the replies // Counts the replies
deleteNote(addressableNote) deleteNote(addressableNote)
@@ -1279,7 +1279,7 @@ object LocalCache : ILocalCache {
.mapNotNull { getAddressableNoteIfExists(it) } .mapNotNull { getAddressableNoteIfExists(it) }
.forEach { deleteNote -> .forEach { deleteNote ->
// must be the same author // must be the same author
if (deleteNote.author?.pubkeyHex == event.pubKey && (deleteNote.createdAt() ?: 0) <= event.createdAt) { if (deleteNote.author?.pubkeyHex == event.pubKey && (deleteNote.createdAt() ?: 0L) <= event.createdAt) {
// Counts the replies // Counts the replies
deleteNote(deleteNote) deleteNote(deleteNote)
@@ -746,7 +746,7 @@ open class Note(
val dayAgo = TimeUtils.oneDayAgo() val dayAgo = TimeUtils.oneDayAgo()
return reports.isNotEmpty() || return reports.isNotEmpty() ||
( (
author?.reports?.any { it.value.firstOrNull { (it.createdAt() ?: 0) > dayAgo } != null } author?.reports?.any { it.value.firstOrNull { (it.createdAt() ?: 0L) > dayAgo } != null }
?: false ?: false
) )
} }
@@ -778,14 +778,14 @@ open class Note(
fun hasBoostedInTheLast5Minutes(loggedIn: User): Boolean { fun hasBoostedInTheLast5Minutes(loggedIn: User): Boolean {
val fiveMinsAgo = TimeUtils.fiveMinutesAgo() val fiveMinsAgo = TimeUtils.fiveMinutesAgo()
return boosts.any { return boosts.any {
it.author == loggedIn && (it.createdAt() ?: 0) > fiveMinsAgo it.author == loggedIn && (it.createdAt() ?: 0L) > fiveMinsAgo
} }
} }
fun hasBoostedInTheLast5Minutes(loggedIn: HexKey): Boolean { fun hasBoostedInTheLast5Minutes(loggedIn: HexKey): Boolean {
val fiveMinsAgo = TimeUtils.fiveMinutesAgo() val fiveMinsAgo = TimeUtils.fiveMinutesAgo()
return boosts.any { return boosts.any {
(it.createdAt() ?: 0) > fiveMinsAgo && it.author?.pubkeyHex == loggedIn (it.createdAt() ?: 0L) > fiveMinsAgo && it.author?.pubkeyHex == loggedIn
} }
} }
@@ -70,14 +70,14 @@ class Chatroom : NotesGatherer {
} }
} }
val createdAt = msg.createdAt() ?: 0 val createdAt = msg.createdAt() ?: 0L
if (createdAt > (newestMessage?.createdAt() ?: 0)) { if (createdAt > (newestMessage?.createdAt() ?: 0L)) {
newestMessage = msg newestMessage = msg
} }
val newSubject = msg.event?.subject() val newSubject = msg.event?.subject()
if (newSubject != null && (msg.createdAt() ?: 0) > (subjectCreatedAt ?: 0)) { if (newSubject != null && (msg.createdAt() ?: 0L) > (subjectCreatedAt ?: 0)) {
subject.tryEmit(newSubject) subject.tryEmit(newSubject)
subjectCreatedAt = msg.createdAt() subjectCreatedAt = msg.createdAt()
} }
@@ -96,7 +96,7 @@ class Chatroom : NotesGatherer {
msg.removeGatherer(this) msg.removeGatherer(this)
if (msg == newestMessage) { if (msg == newestMessage) {
newestMessage = messages.maxByOrNull { it.createdAt() ?: 0 } newestMessage = messages.maxByOrNull { it.createdAt() ?: 0L }
} }
if (msg.event?.subject() == subject.value) { if (msg.event?.subject() == subject.value) {
@@ -127,7 +127,7 @@ class Chatroom : NotesGatherer {
val sorted = messages.sortedWith(DefaultFeedOrder) val sorted = messages.sortedWith(DefaultFeedOrder)
val toKeep = val toKeep =
if ((sorted.firstOrNull()?.createdAt() ?: 0) > TimeUtils.oneWeekAgo()) { if ((sorted.firstOrNull()?.createdAt() ?: 0L) > TimeUtils.oneWeekAgo()) {
// Recent messages, keep last 100 // Recent messages, keep last 100
sorted.take(100).toSet() sorted.take(100).toSet()
} else { } else {
@@ -63,7 +63,7 @@ fun NormalTimeAgo(
val nowStr = stringRes(id = R.string.now) val nowStr = stringRes(id = R.string.now)
val time by val time by
remember(baseNote) { derivedStateOf { timeAgoShort(baseNote.createdAt() ?: 0, nowStr) } } remember(baseNote) { derivedStateOf { timeAgoShort(baseNote.createdAt() ?: 0L, nowStr) } }
Text( Text(
text = time, text = time,
@@ -34,7 +34,7 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText
@Composable @Composable
fun ChatTimeAgo(baseNote: Note) { fun ChatTimeAgo(baseNote: Note) {
val nowStr = stringRes(id = R.string.now) val nowStr = stringRes(id = R.string.now)
val time = remember(baseNote) { timeAgoShort(baseNote.createdAt() ?: 0, nowStr) } val time = remember(baseNote) { timeAgoShort(baseNote.createdAt() ?: 0L, nowStr) }
Text( Text(
text = time, text = time,
@@ -105,7 +105,7 @@ class ChatroomListKnownFeedFilter(
val channelId = (oldNote.event as? ChannelMessageEvent)?.channelId() val channelId = (oldNote.event as? ChannelMessageEvent)?.channelId()
if (newNotePair.key == channelId) { if (newNotePair.key == channelId) {
hasUpdated = true hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) { if ((newNotePair.value.createdAt() ?: 0L) > (oldNote.createdAt() ?: 0L)) {
myNewList = myNewList.replace(oldNote, newNotePair.value) myNewList = myNewList.replace(oldNote, newNotePair.value)
} }
} }
@@ -121,7 +121,7 @@ class ChatroomListKnownFeedFilter(
val noteEvent = (oldNote.event as? EphemeralChatEvent)?.roomId() val noteEvent = (oldNote.event as? EphemeralChatEvent)?.roomId()
if (newNotePair.key == noteEvent) { if (newNotePair.key == noteEvent) {
hasUpdated = true hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) { if ((newNotePair.value.createdAt() ?: 0L) > (oldNote.createdAt() ?: 0L)) {
myNewList = myNewList.replace(oldNote, newNotePair.value) myNewList = myNewList.replace(oldNote, newNotePair.value)
} }
} }
@@ -138,7 +138,7 @@ class ChatroomListKnownFeedFilter(
if (newNotePair.key == oldRoom) { if (newNotePair.key == oldRoom) {
hasUpdated = true hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) { if ((newNotePair.value.createdAt() ?: 0L) > (oldNote.createdAt() ?: 0L)) {
myNewList = myNewList.replace(oldNote, newNotePair.value) myNewList = myNewList.replace(oldNote, newNotePair.value)
} }
} }
@@ -179,7 +179,7 @@ class ChatroomListKnownFeedFilter(
if (channelId in followingChannels && account.isAcceptable(newNote)) { if (channelId in followingChannels && account.isAcceptable(newNote)) {
val lastNote = newRelevantPublicMessages.get(channelId) val lastNote = newRelevantPublicMessages.get(channelId)
if (lastNote != null) { if (lastNote != null) {
if ((newNote.createdAt() ?: 0) > (lastNote.createdAt() ?: 0)) { if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
newRelevantPublicMessages.put(channelId, newNote) newRelevantPublicMessages.put(channelId, newNote)
} }
} else { } else {
@@ -205,7 +205,7 @@ class ChatroomListKnownFeedFilter(
if (room != null && room in followingEphemeralChats && account.isAcceptable(newNote)) { if (room != null && room in followingEphemeralChats && account.isAcceptable(newNote)) {
val lastNote = newRelevantEphemeralChats.get(room) val lastNote = newRelevantEphemeralChats.get(room)
if (lastNote != null) { if (lastNote != null) {
if ((newNote.createdAt() ?: 0) > (lastNote.createdAt() ?: 0)) { if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
newRelevantEphemeralChats.put(room, newNote) newRelevantEphemeralChats.put(room, newNote)
} }
} else { } else {
@@ -241,7 +241,7 @@ class ChatroomListKnownFeedFilter(
) { ) {
val lastNote = newRelevantPrivateMessages.get(roomKey) val lastNote = newRelevantPrivateMessages.get(roomKey)
if (lastNote != null) { if (lastNote != null) {
if ((newNote.createdAt() ?: 0) > (lastNote.createdAt() ?: 0)) { if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
newRelevantPrivateMessages.put(roomKey, newNote) newRelevantPrivateMessages.put(roomKey, newNote)
} }
} else { } else {
@@ -72,7 +72,7 @@ class ChatroomListNewFeedFilter(
if (newNotePair.key == oldRoom) { if (newNotePair.key == oldRoom) {
hasUpdated = true hasUpdated = true
if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) { if ((newNotePair.value.createdAt() ?: 0L) > (oldNote.createdAt() ?: 0L)) {
myNewList = myNewList.replace(oldNote, newNotePair.value) myNewList = myNewList.replace(oldNote, newNotePair.value)
} }
} }
@@ -120,7 +120,7 @@ class ChatroomListNewFeedFilter(
) { ) {
val lastNote = newRelevantPrivateMessages.get(roomKey) val lastNote = newRelevantPrivateMessages.get(roomKey)
if (lastNote != null) { if (lastNote != null) {
if ((newNote.createdAt() ?: 0) > (lastNote.createdAt() ?: 0)) { if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
newRelevantPrivateMessages.put(roomKey, newNote) newRelevantPrivateMessages.put(roomKey, newNote)
} }
} else { } else {
@@ -106,12 +106,12 @@ open class DiscoverChatFeedFilter(
// precache to avoid breaking the contract // precache to avoid breaking the contract
val lastNote = val lastNote =
items.associateWith { note -> items.associateWith { note ->
LocalCache.getPublicChatChannelIfExists(note.idHex)?.lastNote?.createdAt() ?: 0 LocalCache.getPublicChatChannelIfExists(note.idHex)?.lastNote?.createdAt() ?: 0L
} }
val createdNote = val createdNote =
items.associateWith { note -> items.associateWith { note ->
note.createdAt() ?: 0 note.createdAt() ?: 0L
} }
val comparator: Comparator<Note> = val comparator: Comparator<Note> =
@@ -127,7 +127,7 @@ open class DiscoverCommunityFeedFilter(
val createdNote = val createdNote =
items.associateWith { note -> items.associateWith { note ->
note.createdAt() ?: 0 note.createdAt() ?: 0L
} }
val comparator: Comparator<Note> = val comparator: Comparator<Note> =
@@ -80,9 +80,9 @@ open class NIP90ContentDiscoveryResponseFilter(
protected open fun innerApplyFilter(collection: Collection<Note>): Set<Note> { protected open fun innerApplyFilter(collection: Collection<Note>): Set<Note> {
// val params = buildFilterParams(account) // val params = buildFilterParams(account)
val maxNote = collection.filter { acceptableEvent(it) }.maxByOrNull { it.createdAt() ?: 0 } ?: return emptySet() val maxNote = collection.filter { acceptableEvent(it) }.maxByOrNull { it.createdAt() ?: 0L } ?: return emptySet()
if ((maxNote.createdAt() ?: 0) > (latestNote?.createdAt() ?: 0)) { if ((maxNote.createdAt() ?: 0L) > (latestNote?.createdAt() ?: 0L)) {
latestNote = maxNote latestNote = maxNote
} }
@@ -115,7 +115,7 @@ class HomeLiveFilter(
oldList.filter { channel -> oldList.filter { channel ->
val channelTime = (channel as? LiveActivitiesChannel)?.info?.createdAt val channelTime = (channel as? LiveActivitiesChannel)?.info?.createdAt
(channelTime == null || channelTime > fifteenMinsAgo) || (channelTime == null || channelTime > fifteenMinsAgo) ||
(channel.lastNote?.createdAt() ?: 0) > fifteenMinsAgo (channel.lastNote?.createdAt() ?: 0L) > fifteenMinsAgo
} }
val newItemsToBeAdded = applyFilter(newItems) val newItemsToBeAdded = applyFilter(newItems)
@@ -239,7 +239,7 @@ class CardFeedContentState(
(boostsInCard + zapsInCard.map { it.response } + reactionsInCard).groupBy { (boostsInCard + zapsInCard.map { it.response } + reactionsInCard).groupBy {
sdf.format( sdf.format(
Instant Instant
.ofEpochSecond(it.createdAt() ?: 0) .ofEpochSecond(it.createdAt() ?: 0L)
.atZone(ZoneId.systemDefault()) .atZone(ZoneId.systemDefault())
.toLocalDateTime(), .toLocalDateTime(),
) )
@@ -273,7 +273,7 @@ class CardFeedContentState(
user.value.groupBy { user.value.groupBy {
sdf.format( sdf.format(
Instant Instant
.ofEpochSecond(it.createdAt() ?: 0) .ofEpochSecond(it.createdAt() ?: 0L)
.atZone(ZoneId.systemDefault()) .atZone(ZoneId.systemDefault())
.toLocalDateTime(), .toLocalDateTime(),
) )
@@ -43,7 +43,7 @@ abstract class Card {
class BadgeCard( class BadgeCard(
val note: Note, val note: Note,
) : Card() { ) : Card() {
override fun createdAt(): Long = note.createdAt() ?: 0 override fun createdAt(): Long = note.createdAt() ?: 0L
override fun id() = note.idHex override fun id() = note.idHex
} }
@@ -52,7 +52,7 @@ class BadgeCard(
class NoteCard( class NoteCard(
val note: Note, val note: Note,
) : Card() { ) : Card() {
override fun createdAt(): Long = note.createdAt() ?: 0 override fun createdAt(): Long = note.createdAt() ?: 0L
override fun id() = note.idHex override fun id() = note.idHex
} }
@@ -62,7 +62,7 @@ class ZapUserSetCard(
val user: User, val user: User,
val zapEvents: ImmutableList<CombinedZap>, val zapEvents: ImmutableList<CombinedZap>,
) : Card() { ) : Card() {
val createdAt = zapEvents.maxOf { it.createdAt() ?: 0 } val createdAt = zapEvents.maxOfOrNull { it.createdAt() ?: 0L } ?: 0L
override fun createdAt(): Long = createdAt override fun createdAt(): Long = createdAt
@@ -78,9 +78,9 @@ class MultiSetCard(
) : Card() { ) : Card() {
val maxCreatedAt = val maxCreatedAt =
maxOf( maxOf(
zapEvents.maxOfOrNull { it.createdAt() ?: 0 } ?: 0, zapEvents.maxOfOrNull { it.createdAt() ?: 0L } ?: 0L,
likeEvents.maxOfOrNull { it.createdAt() ?: 0 } ?: 0, likeEvents.maxOfOrNull { it.createdAt() ?: 0L } ?: 0L,
boostEvents.maxOfOrNull { it.createdAt() ?: 0 } ?: 0, boostEvents.maxOfOrNull { it.createdAt() ?: 0L } ?: 0L,
) )
val minCreatedAt = val minCreatedAt =
@@ -109,7 +109,7 @@ class MultiSetCard(
class MessageSetCard( class MessageSetCard(
val note: Note, val note: Note,
) : Card() { ) : Card() {
override fun createdAt(): Long = note.createdAt() ?: 0 override fun createdAt(): Long = note.createdAt() ?: 0L
override fun id() = note.idHex override fun id() = note.idHex
} }