From 47d201f936dae8c4c684d5575cbb54298dd04613 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 12 Sep 2025 15:08:10 -0400 Subject: [PATCH] Fixes unnecessary typecasting from long to int in created ats --- .../com/vitorpamplona/amethyst/model/Channel.kt | 2 +- .../com/vitorpamplona/amethyst/model/LocalCache.kt | 14 +++++++------- .../java/com/vitorpamplona/amethyst/model/Note.kt | 6 +++--- .../amethyst/model/privateChats/Chatroom.kt | 10 +++++----- .../amethyst/ui/note/elements/TimeAgo.kt | 2 +- .../ui/screen/loggedIn/chats/feed/ChatTimeAgo.kt | 2 +- .../chats/rooms/dal/ChatroomListKnownFeedFilter.kt | 12 ++++++------ .../chats/rooms/dal/ChatroomListNewFeedFilter.kt | 4 ++-- .../discover/nip28Chats/DiscoverChatFeedFilter.kt | 4 ++-- .../DiscoverCommunityFeedFilter.kt | 2 +- .../dal/NIP90ContentDiscoveryResponseFilter.kt | 4 ++-- .../ui/screen/loggedIn/home/dal/HomeLiveFilter.kt | 2 +- .../loggedIn/notifications/CardFeedContentState.kt | 4 ++-- .../screen/loggedIn/notifications/CardFeedState.kt | 14 +++++++------- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt index 9428b6841..e711e8fe1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt @@ -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 } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index 74d10d291..ae60c2966 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -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) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt index dceb0d3dd..b203748b1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt @@ -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 } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt index ed669a73a..9219c2b92 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt @@ -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 { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/TimeAgo.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/TimeAgo.kt index 197f09d62..9e224b999 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/TimeAgo.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/TimeAgo.kt @@ -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, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/ChatTimeAgo.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/ChatTimeAgo.kt index edef82313..2a6f7e060 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/ChatTimeAgo.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/ChatTimeAgo.kt @@ -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, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt index 09bc8a4b3..4a786a408 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt @@ -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 { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt index ffc24da83..5e9426ee1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt @@ -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 { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt index ab004dfc0..c3b6a5da7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt @@ -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 = diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt index e45a11bed..1e9299271 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt @@ -127,7 +127,7 @@ open class DiscoverCommunityFeedFilter( val createdNote = items.associateWith { note -> - note.createdAt() ?: 0 + note.createdAt() ?: 0L } val comparator: Comparator = diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/dvms/dal/NIP90ContentDiscoveryResponseFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/dvms/dal/NIP90ContentDiscoveryResponseFilter.kt index efb752dc9..5e1102248 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/dvms/dal/NIP90ContentDiscoveryResponseFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/dvms/dal/NIP90ContentDiscoveryResponseFilter.kt @@ -80,9 +80,9 @@ open class NIP90ContentDiscoveryResponseFilter( protected open fun innerApplyFilter(collection: Collection): Set { // 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 } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt index b7a2ce763..62f55d898 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt @@ -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) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt index 175e0bec9..4ee5b7973 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt @@ -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(), ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedState.kt index 67063f904..7baa1fee9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedState.kt @@ -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, ) : 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 }