fix(android): 修复参与者列表在keygen开始后继续增加的bug

问题: 发起者端参与方显示4/3(2-of-3 MPC)
原因: session_started事件后仍继续处理participant_joined事件

修复方案:
1. 在participant_joined处理中检查sessionStatus
2. 如果已是IN_PROGRESS或COMPLETED则忽略新的participant_joined事件
3. session_started时只补全不完整的列表,不覆盖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-27 08:50:39 -08:00
parent 613f85f1c2
commit 7b8105d76c
1 changed files with 24 additions and 6 deletions

View File

@ -343,8 +343,10 @@ class MainViewModel @Inject constructor(
val currentSessionId = _currentSessionId.value
if (currentSessionId != null && event.sessionId == currentSessionId) {
android.util.Log.d("MainViewModel", "Session started event for keygen initiator, triggering keygen")
// Initialize participant list with all N parties (keygen requires all parties)
_sessionParticipants.value = (1..event.thresholdN).map { "参与方 $it" }
// Ensure participant list has exactly N parties (fill if incomplete, don't add more)
if (_sessionParticipants.value.size < event.thresholdN) {
_sessionParticipants.value = (1..event.thresholdN).map { "参与方 $it" }
}
viewModelScope.launch {
startKeygenAsInitiator(
sessionId = currentSessionId,
@ -359,6 +361,10 @@ class MainViewModel @Inject constructor(
val joinKeygenInfo = pendingJoinKeygenInfo
if (joinKeygenInfo != null && event.sessionId == joinKeygenInfo.sessionId) {
android.util.Log.d("MainViewModel", "Session started event for keygen joiner, triggering keygen")
// Ensure participant list has exactly N parties
if (_joinKeygenParticipants.value.size < event.thresholdN) {
_joinKeygenParticipants.value = (1..event.thresholdN).map { "参与方 $it" }
}
startKeygenAsJoiner()
}
@ -366,8 +372,10 @@ class MainViewModel @Inject constructor(
val joinSignInfo = pendingJoinSignInfo
if (joinSignInfo != null && event.sessionId == joinSignInfo.sessionId) {
android.util.Log.d("MainViewModel", "Session started event for sign joiner, triggering sign")
// Initialize participant list with T parties (sign requires T parties)
_coSignParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
// Ensure participant list has exactly T parties
if (_coSignParticipants.value.size < event.thresholdT) {
_coSignParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
}
startSignAsJoiner()
}
@ -376,8 +384,10 @@ class MainViewModel @Inject constructor(
android.util.Log.d("MainViewModel", "Checking for sign initiator: signSessionId=$signSessionId, eventSessionId=${event.sessionId}")
if (signSessionId != null && event.sessionId == signSessionId) {
android.util.Log.d("MainViewModel", "Session started event for sign initiator, triggering sign")
// Initialize participant list with T parties (sign requires T parties)
_signParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
// Ensure participant list has exactly T parties
if (_signParticipants.value.size < event.thresholdT) {
_signParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
}
startSignAsInitiator(event.selectedParties)
} else {
android.util.Log.d("MainViewModel", "NOT triggering sign initiator: signSessionId=$signSessionId, pendingSignInitiatorInfo=${pendingSignInitiatorInfo?.sessionId}")
@ -386,6 +396,14 @@ class MainViewModel @Inject constructor(
"party_joined", "participant_joined" -> {
android.util.Log.d("MainViewModel", "Processing participant_joined event...")
// Don't add participants if keygen/sign has already started
// This prevents duplicate additions after session_started event
val currentStatus = repository.sessionStatus.value
if (currentStatus == SessionStatus.IN_PROGRESS || currentStatus == SessionStatus.COMPLETED) {
android.util.Log.d("MainViewModel", " Session already in progress/completed, ignoring participant_joined")
return@collect
}
// Update participant count for initiator's CreateWallet screen
val currentSessionId = _currentSessionId.value
android.util.Log.d("MainViewModel", " Checking for initiator: currentSessionId=$currentSessionId, eventSessionId=${event.sessionId}")