update logging to new style
This commit is contained in:
+20
-19
@@ -38,6 +38,7 @@ import com.vitorpamplona.quartz.nip64Chess.jester.JesterEvent
|
||||
import com.vitorpamplona.quartz.nip64Chess.jester.JesterGameEvents
|
||||
import com.vitorpamplona.quartz.nip64Chess.jester.JesterProtocol
|
||||
import com.vitorpamplona.quartz.nip64Chess.jester.toJesterEvent
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Android implementation of ChessEventPublisher using Jester protocol.
|
||||
@@ -59,9 +60,9 @@ class AndroidChessPublisher(
|
||||
* Uses ChessEventBroadcaster to ensure relay connections before sending.
|
||||
*/
|
||||
private suspend fun broadcastToChessRelays(event: com.vitorpamplona.quartz.nip01Core.core.Event): Boolean {
|
||||
println("[AndroidChessPublisher] Broadcasting event ${event.id.take(8)} via ChessEventBroadcaster")
|
||||
Log.d("chessdebug") { "[AndroidChessPublisher] Broadcasting event ${event.id.take(8)} via ChessEventBroadcaster" }
|
||||
val result = broadcaster.broadcast(event)
|
||||
println("[AndroidChessPublisher] Broadcast result: ${result.message}")
|
||||
Log.d("chessdebug") { "[AndroidChessPublisher] Broadcast result: ${result.message}" }
|
||||
return result.success
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ class AndroidChessPublisher(
|
||||
account.cache.justConsumeMyOwnEvent(signedEvent)
|
||||
if (success) signedEvent.id else null
|
||||
} catch (e: Exception) {
|
||||
println("[AndroidChessPublisher] publishStart failed: ${e.message}")
|
||||
Log.d("chessdebug") { "[AndroidChessPublisher] publishStart failed: ${e.message}" }
|
||||
null
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ class AndroidChessPublisher(
|
||||
account.cache.justConsumeMyOwnEvent(signedEvent)
|
||||
if (success) signedEvent.id else null
|
||||
} catch (e: Exception) {
|
||||
println("[AndroidChessPublisher] publishMove failed: ${e.message}")
|
||||
Log.d("chessdebug") { "[AndroidChessPublisher] publishMove failed: ${e.message}" }
|
||||
null
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ class AndroidChessPublisher(
|
||||
account.cache.justConsumeMyOwnEvent(signedEvent)
|
||||
success
|
||||
} catch (e: Exception) {
|
||||
println("[AndroidChessPublisher] publishGameEnd failed: ${e.message}")
|
||||
Log.d("chessdebug") { "[AndroidChessPublisher] publishGameEnd failed: ${e.message}" }
|
||||
false
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ class AndroidRelayFetcher(
|
||||
}
|
||||
|
||||
override fun getRelayUrls(): List<String> {
|
||||
println("[AndroidRelayFetcher] getRelayUrls: using ${ChessConfig.CHESS_RELAYS.size} chess relays")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] getRelayUrls: using ${ChessConfig.CHESS_RELAYS.size} chess relays" }
|
||||
return ChessConfig.CHESS_RELAYS
|
||||
}
|
||||
|
||||
@@ -193,7 +194,7 @@ class AndroidRelayFetcher(
|
||||
* 2. Fetch moves that reference the start event via #e tag
|
||||
*/
|
||||
override suspend fun fetchGameEvents(startEventId: String): JesterGameEvents {
|
||||
println("[AndroidRelayFetcher] fetchGameEvents: fetching from relays for startEventId=$startEventId")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchGameEvents: fetching from relays for startEventId=$startEventId" }
|
||||
|
||||
// Filter 1: Fetch the start event by its ID
|
||||
val startEventFilter =
|
||||
@@ -223,7 +224,7 @@ class AndroidRelayFetcher(
|
||||
}
|
||||
}
|
||||
|
||||
println("[AndroidRelayFetcher] fetchGameEvents: found start=${startEvent != null}, moves=${moves.size}")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchGameEvents: found start=${startEvent != null}, moves=${moves.size}" }
|
||||
|
||||
return JesterGameEvents(
|
||||
startEvent = startEvent,
|
||||
@@ -237,30 +238,30 @@ class AndroidRelayFetcher(
|
||||
*/
|
||||
override suspend fun fetchChallenges(onProgress: ((RelayFetchProgress) -> Unit)?): List<JesterEvent> {
|
||||
val relays = chessRelayUrls()
|
||||
println("[AndroidRelayFetcher] fetchChallenges: fetching from ${relays.size} relays: $relays")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchChallenges: fetching from ${relays.size} relays: $relays" }
|
||||
|
||||
if (relays.isEmpty()) {
|
||||
println("[AndroidRelayFetcher] fetchChallenges: WARNING - no connected relays!")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchChallenges: WARNING - no connected relays!" }
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
val filter = ChessFilterBuilder.challengesFilter(userPubkey)
|
||||
println("[AndroidRelayFetcher] fetchChallenges: filter kinds=${filter.kinds}, tags=${filter.tags}, since=${filter.since}, limit=${filter.limit}")
|
||||
println("[AndroidRelayFetcher] fetchChallenges: filter JSON=${filter.toJson()}")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchChallenges: filter kinds=${filter.kinds}, tags=${filter.tags}, since=${filter.since}, limit=${filter.limit}" }
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchChallenges: filter JSON=${filter.toJson()}" }
|
||||
|
||||
val relayFilters = relays.associateWith { listOf(filter) }
|
||||
val events = fetchHelper.fetchEvents(relayFilters, onProgress = onProgress)
|
||||
println("[AndroidRelayFetcher] fetchChallenges: received ${events.size} raw events")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchChallenges: received ${events.size} raw events" }
|
||||
|
||||
// Debug: If no events, also try without #e filter to see if relays have ANY kind 30 events
|
||||
if (events.isEmpty()) {
|
||||
println("[AndroidRelayFetcher] DEBUG: No events with #e filter, trying without tag filter...")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] DEBUG: No events with #e filter, trying without tag filter..." }
|
||||
val debugFilter = ChessFilterBuilder.recentGamesFilter()
|
||||
val debugFilters = relays.associateWith { listOf(debugFilter) }
|
||||
val debugEvents = fetchHelper.fetchEvents(debugFilters, timeoutMs = 10_000)
|
||||
println("[AndroidRelayFetcher] DEBUG: recentGamesFilter (no #e) returned ${debugEvents.size} events")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] DEBUG: recentGamesFilter (no #e) returned ${debugEvents.size} events" }
|
||||
debugEvents.take(5).forEach { e ->
|
||||
println("[AndroidRelayFetcher] DEBUG: kind=${e.kind}, id=${e.id.take(8)}, tags=${e.tags.take(3).map { it.toList() }}")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] DEBUG: kind=${e.kind}, id=${e.id.take(8)}, tags=${e.tags.take(3).map { it.toList() }}" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +287,7 @@ class AndroidRelayFetcher(
|
||||
}
|
||||
}
|
||||
|
||||
println("[AndroidRelayFetcher] fetchChallenges: found ${challenges.size} challenges from ${events.size} events")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchChallenges: found ${challenges.size} challenges from ${events.size} events" }
|
||||
return challenges
|
||||
}
|
||||
|
||||
@@ -356,7 +357,7 @@ class AndroidRelayFetcher(
|
||||
* Uses one-shot fetch for reliability.
|
||||
*/
|
||||
override suspend fun fetchUserGameIds(onProgress: ((RelayFetchProgress) -> Unit)?): Set<String> {
|
||||
println("[AndroidRelayFetcher] fetchUserGameIds: fetching from relays")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchUserGameIds: fetching from relays" }
|
||||
|
||||
// Fetch events authored by user AND events tagging user
|
||||
val authoredFilter = ChessFilterBuilder.userGamesFilter(userPubkey)
|
||||
@@ -386,7 +387,7 @@ class AndroidRelayFetcher(
|
||||
}
|
||||
}
|
||||
|
||||
println("[AndroidRelayFetcher] fetchUserGameIds: found ${gameIds.size} game IDs from ${events.size} events")
|
||||
Log.d("chessdebug") { "[AndroidRelayFetcher] fetchUserGameIds: found ${gameIds.size} game IDs from ${events.size} events" }
|
||||
return gameIds
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -91,6 +91,7 @@ import com.vitorpamplona.amethyst.desktop.subscriptions.createChessSubscriptionW
|
||||
import com.vitorpamplona.amethyst.desktop.subscriptions.createMetadataListSubscription
|
||||
import com.vitorpamplona.amethyst.desktop.subscriptions.rememberSubscription
|
||||
import com.vitorpamplona.quartz.nip64Chess.ChessGameNameGenerator
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
import com.vitorpamplona.quartz.nip64Chess.Color as ChessColor
|
||||
|
||||
/**
|
||||
@@ -119,7 +120,7 @@ fun ChessScreen(
|
||||
ChessConfig.CHESS_RELAYS.forEach { relayUrl ->
|
||||
relayManager.addRelay(relayUrl)
|
||||
}
|
||||
println("[ChessScreen] Added ${ChessConfig.CHESS_RELAYS.size} chess relays to relay manager")
|
||||
Log.d("chessdebug") { "[ChessScreen] Added ${ChessConfig.CHESS_RELAYS.size} chess relays to relay manager" }
|
||||
}
|
||||
|
||||
// Derive stable keys to avoid recomposition from LiveChessGameState identity changes
|
||||
|
||||
+16
-15
@@ -41,6 +41,7 @@ import com.vitorpamplona.quartz.nip64Chess.jester.JesterEvent
|
||||
import com.vitorpamplona.quartz.nip64Chess.jester.JesterGameEvents
|
||||
import com.vitorpamplona.quartz.nip64Chess.jester.JesterProtocol
|
||||
import com.vitorpamplona.quartz.nip64Chess.jester.toJesterEvent
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Desktop implementation of ChessEventPublisher using Jester protocol.
|
||||
@@ -63,9 +64,9 @@ class DesktopChessPublisher(
|
||||
* Uses ChessEventBroadcaster to ensure relay connections before sending.
|
||||
*/
|
||||
private suspend fun broadcastToChessRelays(event: com.vitorpamplona.quartz.nip01Core.core.Event): Boolean {
|
||||
println("[DesktopChessPublisher] Broadcasting event ${event.id.take(8)} via ChessEventBroadcaster")
|
||||
Log.d("chessdebug") { "[DesktopChessPublisher] Broadcasting event ${event.id.take(8)} via ChessEventBroadcaster" }
|
||||
val result = broadcaster.broadcast(event)
|
||||
println("[DesktopChessPublisher] Broadcast result: ${result.message}")
|
||||
Log.d("chessdebug") { "[DesktopChessPublisher] Broadcast result: ${result.message}" }
|
||||
return result.success
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ class DesktopChessPublisher(
|
||||
val success = broadcastToChessRelays(signedEvent)
|
||||
if (success) signedEvent.id else null
|
||||
} catch (e: Exception) {
|
||||
println("[DesktopChessPublisher] publishStart failed: ${e.message}")
|
||||
Log.d("chessdebug") { "[DesktopChessPublisher] publishStart failed: ${e.message}" }
|
||||
null
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ class DesktopChessPublisher(
|
||||
val success = broadcastToChessRelays(signedEvent)
|
||||
if (success) signedEvent.id else null
|
||||
} catch (e: Exception) {
|
||||
println("[DesktopChessPublisher] publishMove failed: ${e.message}")
|
||||
Log.d("chessdebug") { "[DesktopChessPublisher] publishMove failed: ${e.message}" }
|
||||
null
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ class DesktopChessPublisher(
|
||||
val signedEvent = account.signer.sign(template)
|
||||
broadcastToChessRelays(signedEvent)
|
||||
} catch (e: Exception) {
|
||||
println("[DesktopChessPublisher] publishGameEnd failed: ${e.message}")
|
||||
Log.d("chessdebug") { "[DesktopChessPublisher] publishGameEnd failed: ${e.message}" }
|
||||
false
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ class DesktopRelayFetcher(
|
||||
private fun chessRelayUrls(): List<NormalizedRelayUrl> = ChessConfig.CHESS_RELAYS.map { NormalizedRelayUrl(it) }
|
||||
|
||||
override fun getRelayUrls(): List<String> {
|
||||
println("[DesktopRelayFetcher] getRelayUrls: using ${ChessConfig.CHESS_RELAYS.size} chess relays")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] getRelayUrls: using ${ChessConfig.CHESS_RELAYS.size} chess relays" }
|
||||
return ChessConfig.CHESS_RELAYS
|
||||
}
|
||||
|
||||
@@ -182,11 +183,11 @@ class DesktopRelayFetcher(
|
||||
* 2. Fetch moves that reference the start event via #e tag
|
||||
*/
|
||||
override suspend fun fetchGameEvents(startEventId: String): JesterGameEvents {
|
||||
println("[DesktopRelayFetcher] fetchGameEvents: querying cache for startEventId=$startEventId")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchGameEvents: querying cache for startEventId=$startEventId" }
|
||||
|
||||
// Query cache first (populated by subscription)
|
||||
val cachedEvents = DesktopChessEventCache.getGameEvents(startEventId)
|
||||
println("[DesktopRelayFetcher] fetchGameEvents cache: start=${cachedEvents.startEvent != null}, moves=${cachedEvents.moves.size}")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchGameEvents cache: start=${cachedEvents.startEvent != null}, moves=${cachedEvents.moves.size}" }
|
||||
|
||||
// Also do relay query to catch any new events and populate cache
|
||||
// Filter 1: Fetch the start event by its ID
|
||||
@@ -220,7 +221,7 @@ class DesktopRelayFetcher(
|
||||
// Merge: prefer cache start event, merge all moves
|
||||
val allMoves = (cachedEvents.moves + relayMoves).distinctBy { it.id }
|
||||
|
||||
println("[DesktopRelayFetcher] fetchGameEvents: found start=${cachedEvents.startEvent ?: relayStartEvent != null}, moves=${allMoves.size}")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchGameEvents: found start=${cachedEvents.startEvent ?: relayStartEvent != null}, moves=${allMoves.size}" }
|
||||
|
||||
return JesterGameEvents(
|
||||
startEvent = cachedEvents.startEvent ?: relayStartEvent,
|
||||
@@ -233,7 +234,7 @@ class DesktopRelayFetcher(
|
||||
*/
|
||||
override suspend fun fetchChallenges(onProgress: ((RelayFetchProgress) -> Unit)?): List<JesterEvent> {
|
||||
val relays = chessRelayUrls()
|
||||
println("[DesktopRelayFetcher] fetchChallenges: querying cache first, then ${relays.size} chess relays")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchChallenges: querying cache first, then ${relays.size} chess relays" }
|
||||
|
||||
// Query cache for start events that are:
|
||||
// 1. Open challenges (no specific opponent)
|
||||
@@ -246,7 +247,7 @@ class DesktopRelayFetcher(
|
||||
event.pubKey == userPubkey
|
||||
}
|
||||
|
||||
println("[DesktopRelayFetcher] fetchChallenges: found ${cachedStartEvents.size} in cache")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchChallenges: found ${cachedStartEvents.size} in cache" }
|
||||
|
||||
// Also do relay query to catch any new challenges
|
||||
val filter = ChessFilterBuilder.challengesFilter(userPubkey)
|
||||
@@ -264,7 +265,7 @@ class DesktopRelayFetcher(
|
||||
|
||||
// Merge and deduplicate
|
||||
val allStartEvents = (cachedStartEvents + relayStartEvents).distinctBy { it.id }
|
||||
println("[DesktopRelayFetcher] fetchChallenges: total ${allStartEvents.size} after merge")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchChallenges: total ${allStartEvents.size} after merge" }
|
||||
return allStartEvents
|
||||
}
|
||||
|
||||
@@ -273,7 +274,7 @@ class DesktopRelayFetcher(
|
||||
*/
|
||||
override suspend fun fetchUserGameIds(onProgress: ((RelayFetchProgress) -> Unit)?): Set<String> {
|
||||
val relays = chessRelayUrls()
|
||||
println("[DesktopRelayFetcher] fetchUserGameIds: querying cache first, then ${relays.size} chess relays")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchUserGameIds: querying cache first, then ${relays.size} chess relays" }
|
||||
|
||||
val gameIds = mutableSetOf<String>()
|
||||
|
||||
@@ -291,7 +292,7 @@ class DesktopRelayFetcher(
|
||||
event.startEventId()?.let { gameIds.add(it) }
|
||||
}
|
||||
|
||||
println("[DesktopRelayFetcher] fetchUserGameIds: found ${gameIds.size} in cache")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchUserGameIds: found ${gameIds.size} in cache" }
|
||||
|
||||
// Also do relay query to catch any new game IDs
|
||||
val userFilter = ChessFilterBuilder.userGamesFilter(userPubkey)
|
||||
@@ -314,7 +315,7 @@ class DesktopRelayFetcher(
|
||||
}
|
||||
}
|
||||
|
||||
println("[DesktopRelayFetcher] fetchUserGameIds: total ${gameIds.size} after merge")
|
||||
Log.d("chessdebug") { "[DesktopRelayFetcher] fetchUserGameIds: total ${gameIds.size} after merge" }
|
||||
return gameIds
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user