diff --git a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/data/repository/TssRepository.kt b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/data/repository/TssRepository.kt index 47ab8fe7..7ca2fb0c 100644 --- a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/data/repository/TssRepository.kt +++ b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/data/repository/TssRepository.kt @@ -46,6 +46,11 @@ class TssRepository @Inject constructor( private var messageCollectionJob: Job? = null private var sessionEventJob: Job? = null + /** + * Get the current party ID + */ + fun getPartyId(): String = partyId + // Track current message routing params for reconnection recovery private var currentMessageRoutingSessionId: String? = null private var currentMessageRoutingPartyIndex: Int? = null diff --git a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt index d8beb014..189cce95 100644 --- a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt +++ b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt @@ -235,13 +235,35 @@ class MainViewModel @Inject constructor( onSuccess = { sessionResult -> _createdInviteCode.value = sessionResult.inviteCode _currentSessionId.value = sessionResult.sessionId - // Add self as first participant - _sessionParticipants.value = listOf(participantName) // Store party index for later use _currentRound.value = 0 - _uiState.update { it.copy(isLoading = false) } android.util.Log.d("MainViewModel", "Keygen session created: sessionId=${sessionResult.sessionId}, partyIndex=${sessionResult.partyIndex}") + + // Fetch current session status to get all participants (including server-party-co-managed) + // This matches Electron's behavior of calling getSessionStatus after session creation + val statusResult = repository.getSessionStatus(sessionResult.sessionId) + statusResult.fold( + onSuccess = { status -> + val participantNames = status.participants.mapIndexed { index, p -> + if (p.partyId == repository.getPartyId()) { + participantName // Use the name provided by user for self + } else { + "参与方 ${index + 1}" // Generic name for others + } + } + _sessionParticipants.value = participantNames + android.util.Log.d("MainViewModel", "Session status fetched: ${status.participants.size} participants already joined") + android.util.Log.d("MainViewModel", " Participants: ${status.participants.map { it.partyId }}") + }, + onFailure = { e -> + // Fallback to just self if status fetch fails + _sessionParticipants.value = listOf(participantName) + android.util.Log.w("MainViewModel", "Failed to fetch session status: ${e.message}, using self only") + } + ) + + _uiState.update { it.copy(isLoading = false) } }, onFailure = { e -> _uiState.update { it.copy(isLoading = false, error = e.message) }