fix(chess): exclude own games from spectator list

Skip adding games to spectatingGames when the user is a participant
(playerPubkey or opponentPubkey matches userPubkey) or when the game
is already finished.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-03-23 15:41:38 +01:00
parent 638bdb7b2d
commit 8c69105fdb
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.commons.chess
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip64Chess.Color
import com.vitorpamplona.quartz.nip64Chess.GameStatus
import com.vitorpamplona.quartz.nip64Chess.LiveChessGameState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
@@ -497,6 +498,14 @@ class ChessLobbyState(
_activeGames.update { it + (gameId to state) }
return
}
// Don't add own games to spectating list
if (state.playerPubkey == userPubkey || state.opponentPubkey == userPubkey) {
return
}
// Don't add finished games to spectating list
if (state.gameStatus.value is GameStatus.Finished) {
return
}
_spectatingGames.update { it + (gameId to state) }
}