diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessEventPolling.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessEventPolling.kt index 91a46df5c..277ddf542 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessEventPolling.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessEventPolling.kt @@ -161,6 +161,10 @@ class ChessPollingDelegate( */ fun removeGameId(gameId: String) { activeGameIdsFlow.value = activeGameIdsFlow.value - gameId + // If this was the focused game, clear focus to stop re-polling a finished game + if (_focusedGameId.value == gameId) { + _focusedGameId.value = null + } } /** diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessLobbyLogic.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessLobbyLogic.kt index 4ed8ed9d4..49e218047 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessLobbyLogic.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/chess/ChessLobbyLogic.kt @@ -677,6 +677,8 @@ class ChessLobbyLogic( Log.d("chessdebug", "[Lobby] refreshGame: SKIPPED game ${startEventId.take(8)} - loaded ${TimeUtils.now() - lastLoaded}s ago") return } + // Mark immediately to prevent concurrent fetches for the same game + recentlyLoadedGames[startEventId] = TimeUtils.now() Log.d("chessdebug", "[Lobby] refreshGame: fetching game ${startEventId.take(8)} from relays") val events = fetcher.fetchGameEvents(startEventId)