revert: keep INostrClient/NostrClient naming and restore onEose/isLive
Reverts three naming changes from the previous refactor: - Interface stays INostrClient (not NostrClient) - Class stays NostrClient (not DefaultNostrClient) - onEose stays onEose (not onCaughtUp) - isLive stays isLive (not isRealTime) All other renames from the API simplification are preserved: subscribe, unsubscribe, publish, count, fetchAll, fetchFirst, etc. https://claude.ai/code/session_01JPcYCcRx5eZN4GvgGxGwbf
This commit is contained in:
+6
-6
@@ -131,11 +131,11 @@ class AccountManager internal constructor(
|
||||
// --- Dedicated NIP-46 client (isolated from general relay pool) ---
|
||||
|
||||
private val nip46ClientMutex = Mutex()
|
||||
private var nip46Client: DefaultDefaultNostrClient? = null
|
||||
private var nip46Client: NostrClient? = null
|
||||
|
||||
private suspend fun getOrCreateNip46Client(): DefaultNostrClient =
|
||||
private suspend fun getOrCreateNip46Client(): INostrClient =
|
||||
nip46ClientMutex.withLock {
|
||||
nip46Client ?: DefaultNostrClient(
|
||||
nip46Client ?: NostrClient(
|
||||
BasicOkHttpWebSocket.Builder(DesktopHttpClient::getHttpClient),
|
||||
).also {
|
||||
nip46Client = it
|
||||
@@ -155,7 +155,7 @@ class AccountManager internal constructor(
|
||||
* but we must wait for the websocket to be ready before sending requests.
|
||||
*/
|
||||
private suspend fun awaitNip46RelayConnection(
|
||||
client: DefaultNostrClient,
|
||||
client: INostrClient,
|
||||
targetRelays: Set<NormalizedRelayUrl>,
|
||||
) {
|
||||
withTimeout(NIP46_RELAY_CONNECT_TIMEOUT_MS) {
|
||||
@@ -302,7 +302,7 @@ class AccountManager internal constructor(
|
||||
|
||||
suspend fun loginWithBunker(bunkerUri: String): Result<AccountState.LoggedIn> {
|
||||
val listener = createLoginRelayListener()
|
||||
var client: DefaultDefaultNostrClient? = null
|
||||
var client: NostrClient? = null
|
||||
try {
|
||||
val ephemeralKeyPair = KeyPair()
|
||||
val ephemeralSigner = NostrSignerInternal(ephemeralKeyPair)
|
||||
@@ -363,7 +363,7 @@ class AccountManager internal constructor(
|
||||
|
||||
suspend fun loginWithNostrConnect(onUriGenerated: (String) -> Unit): Result<AccountState.LoggedIn> {
|
||||
val listener = createLoginRelayListener()
|
||||
var client: DefaultDefaultNostrClient? = null
|
||||
var client: NostrClient? = null
|
||||
try {
|
||||
val ephemeralKeyPair = KeyPair()
|
||||
val uriData = NostrConnectLoginUseCase.generateUri(ephemeralKeyPair, NIP46_RELAYS, "Amethyst%20Desktop")
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ fun ChessScreen(
|
||||
onEvent = { event, _, _, _ ->
|
||||
viewModel.handleIncomingEvent(event)
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
// ChessLobbyLogic handles loading state internally
|
||||
},
|
||||
)
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.amethyst.desktop.network
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
@@ -44,10 +44,10 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
open class RelayConnectionManager(
|
||||
websocketBuilder: WebsocketBuilder,
|
||||
) : RelayConnectionListener {
|
||||
private val _client = DefaultNostrClient(websocketBuilder)
|
||||
private val _client = NostrClient(websocketBuilder)
|
||||
|
||||
/** Exposes the underlying NostrClient for subscription coordinators */
|
||||
val client: com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient get() = _client
|
||||
/** Exposes the underlying INostrClient for subscription coordinators */
|
||||
val client: com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient get() = _client
|
||||
|
||||
private val _relayStatuses = MutableStateFlow<Map<NormalizedRelayUrl, RelayStatus>>(emptyMap())
|
||||
val relayStatuses: StateFlow<Map<NormalizedRelayUrl, RelayStatus>> = _relayStatuses.asStateFlow()
|
||||
@@ -145,7 +145,7 @@ open class RelayConnectionManager(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+11
-11
@@ -58,7 +58,7 @@ private val CHESS_EVENT_KINDS =
|
||||
class DesktopChessSubscriptionController(
|
||||
private val relayManager: RelayConnectionManager,
|
||||
private val onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
private val onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
private val onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
) : ChessSubscriptionController {
|
||||
private val _currentState = MutableStateFlow<ChessSubscriptionState?>(null)
|
||||
override val currentState: StateFlow<ChessSubscriptionState?> = _currentState.asStateFlow()
|
||||
@@ -98,7 +98,7 @@ class DesktopChessSubscriptionController(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -106,16 +106,16 @@ class DesktopChessSubscriptionController(
|
||||
if (event.kind in CHESS_EVENT_KINDS) {
|
||||
DesktopChessEventCache.add(event)
|
||||
}
|
||||
onEvent(event, isRealTime, relay, forFilters)
|
||||
onEvent(event, isLive, relay, forFilters)
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
// Track EOSE time for this relay for efficient re-subscription
|
||||
relayEoseTimes[relay] = TimeUtils.now()
|
||||
onCaughtUp(relay, forFilters)
|
||||
onEose(relay, forFilters)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -162,7 +162,7 @@ class DesktopChessSubscriptionController(
|
||||
* @param activeGameIds Set of game IDs the user is actively playing (for game-specific filters)
|
||||
* @param opponentPubkeys Set of opponent pubkeys for active games (for move filtering)
|
||||
* @param onEvent Callback for incoming events
|
||||
* @param onCaughtUp Callback for EOSE (End of Stored Events)
|
||||
* @param onEose Callback for EOSE (End of Stored Events)
|
||||
*/
|
||||
fun createChessSubscriptionWithGames(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
@@ -170,7 +170,7 @@ fun createChessSubscriptionWithGames(
|
||||
activeGameIds: Set<String> = emptySet(),
|
||||
opponentPubkeys: Set<String> = emptySet(),
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (relays.isEmpty()) return null
|
||||
|
||||
@@ -197,7 +197,7 @@ fun createChessSubscriptionWithGames(
|
||||
filters = filters,
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -207,11 +207,11 @@ fun createChessSubscriptionWithGames(
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use createChessSubscriptionWithGames for active game support",
|
||||
ReplaceWith("createChessSubscriptionWithGames(relays, userPubkey, emptySet(), emptySet(), onEvent, onCaughtUp)"),
|
||||
ReplaceWith("createChessSubscriptionWithGames(relays, userPubkey, emptySet(), emptySet(), onEvent, onEose)"),
|
||||
)
|
||||
fun createChessSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
userPubkey: String,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? = createChessSubscriptionWithGames(relays, userPubkey, emptySet(), emptySet(), onEvent, onCaughtUp)
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? = createChessSubscriptionWithGames(relays, userPubkey, emptySet(), emptySet(), onEvent, onEose)
|
||||
|
||||
+4
-4
@@ -30,7 +30,7 @@ import com.vitorpamplona.amethyst.desktop.model.DesktopDmRelayState
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -73,7 +73,7 @@ import kotlin.time.Duration.Companion.seconds
|
||||
* ```
|
||||
*/
|
||||
class DesktopRelaySubscriptionsCoordinator(
|
||||
private val client: NostrClient,
|
||||
private val client: INostrClient,
|
||||
private val scope: CoroutineScope,
|
||||
private val indexRelays: Set<NormalizedRelayUrl>,
|
||||
private val localCache: DesktopLocalCache,
|
||||
@@ -180,7 +180,7 @@ class DesktopRelaySubscriptionsCoordinator(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -284,7 +284,7 @@ class DesktopRelaySubscriptionsCoordinator(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+28
-28
@@ -39,14 +39,14 @@ fun createGlobalFeedSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
limit: Int = 50,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("global-feed"),
|
||||
filters = listOf(FilterBuilders.textNotesGlobal(limit = limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ fun createFollowingFeedSubscription(
|
||||
followedUsers: List<String>,
|
||||
limit: Int = 50,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (followedUsers.isEmpty()) return null
|
||||
|
||||
@@ -66,7 +66,7 @@ fun createFollowingFeedSubscription(
|
||||
filters = listOf(FilterBuilders.textNotesFromAuthors(followedUsers, limit = limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ fun createContactListSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
pubKeyHex: String,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("contacts-${pubKeyHex.take(8)}"),
|
||||
filters = listOf(FilterBuilders.contactList(pubKeyHex)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -94,14 +94,14 @@ fun createNoteSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
noteId: String,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("note-${noteId.take(8)}"),
|
||||
filters = listOf(FilterBuilders.byIds(listOf(noteId))),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ fun createThreadRepliesSubscription(
|
||||
noteId: String,
|
||||
limit: Int = 200,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("thread-${noteId.take(8)}"),
|
||||
@@ -129,7 +129,7 @@ fun createThreadRepliesSubscription(
|
||||
),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -144,7 +144,7 @@ fun createSearchPeopleSubscription(
|
||||
searchQuery: String,
|
||||
limit: Int = 50,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onClosed: (NormalizedRelayUrl, String, List<Filter>?) -> Unit = { _, _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (searchQuery.isBlank()) return null
|
||||
@@ -154,7 +154,7 @@ fun createSearchPeopleSubscription(
|
||||
filters = listOf(FilterBuilders.searchPeople(searchQuery, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
onClosed = onClosed,
|
||||
)
|
||||
}
|
||||
@@ -171,7 +171,7 @@ fun createSearchNotesSubscription(
|
||||
searchQuery: String,
|
||||
limit: Int = 50,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (searchQuery.isBlank()) return null
|
||||
|
||||
@@ -180,7 +180,7 @@ fun createSearchNotesSubscription(
|
||||
filters = listOf(FilterBuilders.searchNotes(searchQuery, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ fun createZapsSubscription(
|
||||
eventIds: List<String>,
|
||||
limit: Int = 100,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (eventIds.isEmpty()) return null
|
||||
|
||||
@@ -204,7 +204,7 @@ fun createZapsSubscription(
|
||||
filters = listOf(FilterBuilders.zapsForEvents(eventIds, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ fun createReactionsSubscription(
|
||||
eventIds: List<String>,
|
||||
limit: Int = 100,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (eventIds.isEmpty()) return null
|
||||
|
||||
@@ -228,7 +228,7 @@ fun createReactionsSubscription(
|
||||
filters = listOf(FilterBuilders.reactionsForEvents(eventIds, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ fun createRepliesSubscription(
|
||||
eventIds: List<String>,
|
||||
limit: Int = 100,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (eventIds.isEmpty()) return null
|
||||
|
||||
@@ -252,7 +252,7 @@ fun createRepliesSubscription(
|
||||
filters = listOf(FilterBuilders.repliesForEvents(eventIds, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ fun createRepostsSubscription(
|
||||
eventIds: List<String>,
|
||||
limit: Int = 100,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (eventIds.isEmpty()) return null
|
||||
|
||||
@@ -276,7 +276,7 @@ fun createRepostsSubscription(
|
||||
filters = listOf(FilterBuilders.repostsForEvents(eventIds, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -287,14 +287,14 @@ fun createLongFormFeedSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
limit: Int = 30,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("longform-feed"),
|
||||
filters = listOf(FilterBuilders.longFormGlobal(limit = limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -305,7 +305,7 @@ fun createFollowingLongFormFeedSubscription(
|
||||
followedUsers: List<String>,
|
||||
limit: Int = 30,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (followedUsers.isEmpty()) return null
|
||||
|
||||
@@ -314,7 +314,7 @@ fun createFollowingLongFormFeedSubscription(
|
||||
filters = listOf(FilterBuilders.longFormFromAuthors(followedUsers, limit = limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ fun createChessSubscription(
|
||||
userPubkey: String,
|
||||
limit: Int = 100,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("chess-${userPubkey.take(8)}"),
|
||||
@@ -348,5 +348,5 @@ fun createChessSubscription(
|
||||
),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
+8
-8
@@ -144,7 +144,7 @@ fun createNip04DmInboxSubscription(
|
||||
since: Long? = null,
|
||||
limit: Int? = null,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (relays.isEmpty() || userPubKeyHex.length != 64) return null
|
||||
|
||||
@@ -153,7 +153,7 @@ fun createNip04DmInboxSubscription(
|
||||
filters = listOf(FilterDMs.nip04ToMe(userPubKeyHex, since, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ fun createNip04DmOutboxSubscription(
|
||||
since: Long? = null,
|
||||
limit: Int? = null,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (relays.isEmpty() || userPubKeyHex.length != 64) return null
|
||||
|
||||
@@ -176,7 +176,7 @@ fun createNip04DmOutboxSubscription(
|
||||
filters = listOf(FilterDMs.nip04FromMe(userPubKeyHex, since, limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ fun createGiftWrapSubscription(
|
||||
userPubKeyHex: HexKey,
|
||||
since: Long? = null,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (relays.isEmpty() || userPubKeyHex.length != 64) return null
|
||||
|
||||
@@ -198,7 +198,7 @@ fun createGiftWrapSubscription(
|
||||
filters = listOf(FilterDMs.giftWrapsToMe(userPubKeyHex, since)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ fun createDmConversationSubscription(
|
||||
conversationPubKeys: Set<HexKey>,
|
||||
since: Long? = null,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (conversationPubKeys.isEmpty() || userPubKeyHex.length != 64) return null
|
||||
|
||||
@@ -225,6 +225,6 @@ fun createDmConversationSubscription(
|
||||
filters = FilterDMs.nip04Conversation(userPubKeyHex, conversationPubKeys, since),
|
||||
relays = allRelays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
+10
-10
@@ -32,7 +32,7 @@ fun createMetadataSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
pubKeyHex: String,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
// Validate pubkey length
|
||||
if (pubKeyHex.length != 64) {
|
||||
@@ -43,7 +43,7 @@ fun createMetadataSubscription(
|
||||
filters = listOf(FilterBuilders.userMetadata(pubKeyHex)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ fun createBatchMetadataSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
pubKeyHexList: List<String>,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
// Filter out invalid pubkeys
|
||||
val validPubkeys = pubKeyHexList.filter { it.length == 64 }
|
||||
@@ -67,7 +67,7 @@ fun createBatchMetadataSubscription(
|
||||
filters = listOf(FilterBuilders.userMetadataBatch(validPubkeys)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ fun createMetadataListSubscription(
|
||||
relays: Set<NormalizedRelayUrl>,
|
||||
pubKeys: List<String>,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig? {
|
||||
if (pubKeys.isEmpty()) return null
|
||||
|
||||
@@ -88,7 +88,7 @@ fun createMetadataListSubscription(
|
||||
filters = listOf(FilterBuilders.userMetadataMultiple(pubKeys)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ fun createUserPostsSubscription(
|
||||
pubKeyHex: String,
|
||||
limit: Int = 50,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("posts-${pubKeyHex.take(8)}"),
|
||||
@@ -111,7 +111,7 @@ fun createUserPostsSubscription(
|
||||
),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -122,12 +122,12 @@ fun createNotificationsSubscription(
|
||||
pubKeyHex: String,
|
||||
limit: Int = 100,
|
||||
onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
): SubscriptionConfig =
|
||||
SubscriptionConfig(
|
||||
subId = generateSubId("notif-${pubKeyHex.take(8)}"),
|
||||
filters = listOf(FilterBuilders.notificationsForUser(pubKeyHex, limit = limit)),
|
||||
relays = relays,
|
||||
onEvent = onEvent,
|
||||
onCaughtUp = onCaughtUp,
|
||||
onEose = onEose,
|
||||
)
|
||||
|
||||
+5
-5
@@ -45,7 +45,7 @@ data class SubscriptionConfig(
|
||||
val filters: List<Filter>,
|
||||
val relays: Set<NormalizedRelayUrl>,
|
||||
val onEvent: (Event, Boolean, NormalizedRelayUrl, List<Filter>?) -> Unit,
|
||||
val onCaughtUp: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
val onEose: (NormalizedRelayUrl, List<Filter>?) -> Unit = { _, _ -> },
|
||||
val onClosed: (NormalizedRelayUrl, String, List<Filter>?) -> Unit = { _, _, _ -> },
|
||||
)
|
||||
|
||||
@@ -83,18 +83,18 @@ fun rememberSubscription(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
cfg.onEvent(event, isRealTime, relay, forFilters)
|
||||
cfg.onEvent(event, isLive, relay, forFilters)
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
cfg.onCaughtUp(relay, forFilters)
|
||||
cfg.onEose(relay, forFilters)
|
||||
}
|
||||
|
||||
override fun onClosed(
|
||||
|
||||
+2
-2
@@ -222,7 +222,7 @@ fun ArticleReaderScreen(
|
||||
}
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
eoseReceived = true
|
||||
},
|
||||
)
|
||||
@@ -335,7 +335,7 @@ fun ArticleReaderScreen(
|
||||
.toSet()
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
+3
-3
@@ -168,7 +168,7 @@ fun BookmarksScreen(
|
||||
publicBookmarkIds = pubIds
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
hasReceivedEose = true
|
||||
isLoading = false
|
||||
},
|
||||
@@ -214,7 +214,7 @@ fun BookmarksScreen(
|
||||
subscriptionsCoordinator?.consumeEvent(event, relay)
|
||||
publicEventState.addItem(event)
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -236,7 +236,7 @@ fun BookmarksScreen(
|
||||
subscriptionsCoordinator?.consumeEvent(event, relay)
|
||||
privateEventState.addItem(event)
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
@@ -439,7 +439,7 @@ private suspend fun fetchMetadataForUsers(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -457,7 +457,7 @@ private suspend fun fetchMetadataForUsers(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -1061,7 +1061,7 @@ private suspend fun fetchUserLightningAddress(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -1078,7 +1078,7 @@ private suspend fun fetchUserLightningAddress(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+1
-1
@@ -228,7 +228,7 @@ fun NotificationsScreen(
|
||||
|
||||
notificationState.addItem(notification)
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
eoseReceivedCount++
|
||||
},
|
||||
)
|
||||
|
||||
@@ -261,7 +261,7 @@ fun ReadsScreen(
|
||||
eventState.addItem(event)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
eoseReceivedCount++
|
||||
},
|
||||
)
|
||||
@@ -277,7 +277,7 @@ fun ReadsScreen(
|
||||
eventState.addItem(event)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
eoseReceivedCount++
|
||||
},
|
||||
)
|
||||
|
||||
@@ -202,7 +202,7 @@ fun SearchScreen(
|
||||
}
|
||||
}
|
||||
},
|
||||
onCaughtUp = { relay, _ ->
|
||||
onEose = { relay, _ ->
|
||||
state.updateRelayState(relay.url, RelaySyncStatus.EOSE_RECEIVED)
|
||||
state.stopSearching("people-search")
|
||||
},
|
||||
@@ -236,7 +236,7 @@ fun SearchScreen(
|
||||
}
|
||||
}
|
||||
},
|
||||
onCaughtUp = { relay, _ ->
|
||||
onEose = { relay, _ ->
|
||||
state.updateRelayState(relay.url, RelaySyncStatus.EOSE_RECEIVED)
|
||||
state.stopSearching("adv-search")
|
||||
},
|
||||
|
||||
@@ -131,7 +131,7 @@ fun ThreadScreen(
|
||||
subscriptionsCoordinator?.consumeEvent(event, relay)
|
||||
levelCache[event.id] = 0
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
rootNoteEoseReceived = true
|
||||
},
|
||||
)
|
||||
@@ -149,7 +149,7 @@ fun ThreadScreen(
|
||||
onEvent = { event, _, relay, _ ->
|
||||
subscriptionsCoordinator?.consumeEvent(event, relay)
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
+7
-7
@@ -190,7 +190,7 @@ fun UserProfileScreen(
|
||||
onEvent = { event, _, relay, _ ->
|
||||
subscriptionsCoordinator?.consumeEvent(event, relay)
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -232,7 +232,7 @@ fun UserProfileScreen(
|
||||
contactListLoaded = true
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
eoseReceivedCount++
|
||||
|
||||
// Wait for EOSE from at least 2 relays or all relays before enabling button
|
||||
@@ -294,7 +294,7 @@ fun UserProfileScreen(
|
||||
localCache.cacheFollowingCount(pubKeyHex, count)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -329,7 +329,7 @@ fun UserProfileScreen(
|
||||
localCache.cacheFollowerCount(pubKeyHex, count)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -356,7 +356,7 @@ fun UserProfileScreen(
|
||||
pictureEvents.add(event)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -383,7 +383,7 @@ fun UserProfileScreen(
|
||||
articleEvents.add(event)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -410,7 +410,7 @@ fun UserProfileScreen(
|
||||
highlightEvents.add(event)
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ -> },
|
||||
onEose = { _, _ -> },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ class ChatroomListState(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ package com.vitorpamplona.amethyst.desktop.ui.chats
|
||||
|
||||
import com.vitorpamplona.amethyst.commons.ui.chat.DmBroadcastStatus
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.publishAndConfirmDetailed
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class DmSendTracker(
|
||||
private val client: NostrClient,
|
||||
private val client: INostrClient,
|
||||
) {
|
||||
private val _status = MutableStateFlow<DmBroadcastStatus>(DmBroadcastStatus.Idle)
|
||||
val status: StateFlow<DmBroadcastStatus> = _status.asStateFlow()
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ fun NewDmDialog(
|
||||
}
|
||||
}
|
||||
},
|
||||
onCaughtUp = { _, _ ->
|
||||
onEose = { _, _ ->
|
||||
searchState.endRelaySearch()
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user