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:
+9
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.commons.chess
|
|||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.quartz.nip64Chess.Color
|
import com.vitorpamplona.quartz.nip64Chess.Color
|
||||||
|
import com.vitorpamplona.quartz.nip64Chess.GameStatus
|
||||||
import com.vitorpamplona.quartz.nip64Chess.LiveChessGameState
|
import com.vitorpamplona.quartz.nip64Chess.LiveChessGameState
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@@ -497,6 +498,14 @@ class ChessLobbyState(
|
|||||||
_activeGames.update { it + (gameId to state) }
|
_activeGames.update { it + (gameId to state) }
|
||||||
return
|
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) }
|
_spectatingGames.update { it + (gameId to state) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user