use typealiases as references to reduce files changed

This commit is contained in:
nrobi144
2026-01-01 12:41:13 +02:00
parent 4bc7e86448
commit 9b330164a7
494 changed files with 995 additions and 898 deletions
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.commons.model.nip56Reports
import com.vitorpamplona.amethyst.commons.model.Note
import com.vitorpamplona.amethyst.commons.model.User
import com.vitorpamplona.amethyst.commons.model.UserDependencies
import com.vitorpamplona.amethyst.commons.relays.EOSERelayList
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip56Reports.ReportEvent
import com.vitorpamplona.quartz.nip56Reports.ReportType
@@ -33,6 +34,9 @@ import kotlinx.coroutines.flow.update
class UserReportCache : UserDependencies {
val receivedReportsByAuthor = MutableStateFlow(mapOf<User, Set<Note>>())
/** Tracks EOSE (End Of Stored Events) for relay subscriptions */
val latestEOSEs = EOSERelayList()
fun addReport(note: Note) {
val author = note.author ?: return
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.commons.model.trustedAssertions
import com.vitorpamplona.amethyst.commons.model.AddressableNote
import com.vitorpamplona.amethyst.commons.model.User
import com.vitorpamplona.amethyst.commons.model.UserDependencies
import com.vitorpamplona.amethyst.commons.relays.EOSERelayList
import com.vitorpamplona.amethyst.commons.util.PlatformNumberFormatter
import com.vitorpamplona.quartz.experimental.relationshipStatus.ContactCardEvent
import kotlinx.coroutines.Dispatchers
@@ -36,6 +37,9 @@ import kotlinx.coroutines.flow.update
class UserCardsCache : UserDependencies {
val receivedCards = MutableStateFlow(mapOf<User, AddressableNote>())
/** Tracks EOSE (End Of Stored Events) for relay subscriptions */
val latestEOSEs = EOSERelayList()
fun addCard(note: AddressableNote) {
val author = note.author ?: return
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons.relays
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
typealias SincePerRelayMap = MutableMap<NormalizedRelayUrl, MutableTime>
/**
* Tracks EOSE (End Of Stored Events) timestamps for relay subscriptions.
* Used by UserCardsCache and similar classes to manage relay subscription state.
*/
class EOSERelayList {
var relayList: SincePerRelayMap = mutableMapOf()
fun addOrUpdate(
relayUrl: NormalizedRelayUrl,
time: Long,
) {
val eose = relayList[relayUrl]
if (eose == null) {
relayList[relayUrl] = MutableTime(time)
} else {
eose.updateIfNewer(time)
}
}
fun clear() {
relayList = mutableMapOf()
}
fun since() = relayList
fun newEose(
relay: NormalizedRelayUrl,
time: Long,
) = addOrUpdate(relay, time)
}
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons.relays
/*
* Wrapper class to allow changing in EOSE without modifying the list it is included within
*/
class MutableTime(
startTime: Long,
) {
var time: Long = startTime
private set
override fun toString(): String = time.toString()
fun updateIfNewer(newTime: Long) {
if (newTime > time) {
time = newTime
}
}
fun updateIfOlder(newTime: Long) {
if (newTime < time) {
time = newTime
}
}
fun minus(delta: Int) = MutableTime(time - delta)
fun copy() = MutableTime(time)
}