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