Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import com.ruleup.verification.domain.usecase.AgreeVerificationConsentUseCase
import com.ruleup.verification.domain.usecase.CheckVerificationAccessUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import java.io.IOException
import java.time.YearMonth
Expand Down Expand Up @@ -467,7 +469,7 @@
// 빈 피드는 같은 화면에서 여러 번 그려질 수 있어 노출 로그는 한 번만 남긴다.
private var emptyFeedLogged = false

private fun load(

Check failure on line 472 in challenge/presentation/src/main/kotlin/com/ruleup/challenge/presentation/detail/viewmodel/ChallengeDetailViewModel.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=RuleUp-ASM_Android&issues=AaEbzSYIo_WJ8HMKdcOQ&open=AaEbzSYIo_WJ8HMKdcOQ&pullRequest=612
challengeId: String,
force: Boolean = false,
) {
Expand All @@ -484,14 +486,20 @@
dispatch(ChallengeDetailReducerEvent.Loading(challengeId))
runCatching { challengeRepository.getChallenge(challengeId) }
.onSuccess { detail ->
// 셋업 요구사항은 실패해도(미구현/멤버 아님 등) 상세 렌더를 막지 않도록 흡수한다.
val setup = runCatching { challengeRepository.getSetupInfo(challengeId) }.getOrNull()
// 그룹 멤버는 방을 먼저 받아 둔다 — 상세만 먼저 그리면 참여 전 화면이 잠깐 떴다가 방 화면으로 바뀐다.
val prefetchedRoom =
if (detail.mode.isGroup && detail.myRole.isMember) {
runCatching { roomRepository.getRoom(challengeId) }.getOrNull()
} else {
null
val (setup, prefetchedRoom) =
coroutineScope {
// 셋업 요구사항은 실패해도(미구현/멤버 아님 등) 상세 렌더를 막지 않도록 흡수한다.
val setup = async { runCatching { challengeRepository.getSetupInfo(challengeId) }.getOrNull() }
// 그룹 멤버는 방을 먼저 받아 둔다 — 상세만 먼저 그리면 참여 전 화면이 잠깐 떴다가 방 화면으로 바뀐다.
val room =
async {
if (detail.mode.isGroup && detail.myRole.isMember) {
runCatching { roomRepository.getRoom(challengeId) }.getOrNull()
} else {
null
}
}
setup.await() to room.await()
}
dispatch(
ChallengeDetailReducerEvent.Loaded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.ruleup.domain.helper.NavigationHelper
import com.ruleup.ui.error.userFacingMessage
import com.ruleup.ui.mvi.MviViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -239,15 +241,18 @@ class ChallengeSettingsViewModel
) {
viewModelScope.launch {
dispatch(ChallengeSettingsReducerEvent.Loading(challengeId))
runCatching { challengeRepository.getSettings(challengeId) }
.onSuccess { settings ->
// 정원 하한 계산에 현재 인원이 필요한데 settings 응답에 없다.
runCatching {
coroutineScope {
// 정원 하한 계산에 현재 인원이 필요한데 settings 응답에 없다. 인원 조회 실패는 흡수한다.
val participants =
runCatching { challengeRepository.getChallenge(challengeId).participantCount }.getOrNull()
dispatch(ChallengeSettingsReducerEvent.Loaded(settings, participants, preserveEdits))
}.onFailure {
dispatch(ChallengeSettingsReducerEvent.Failed(it.userFacingMessage("설정을 불러오지 못했어요")))
async { runCatching { challengeRepository.getChallenge(challengeId).participantCount }.getOrNull() }
challengeRepository.getSettings(challengeId) to participants.await()
}
}.onSuccess { (settings, participants) ->
dispatch(ChallengeSettingsReducerEvent.Loaded(settings, participants, preserveEdits))
}.onFailure {
dispatch(ChallengeSettingsReducerEvent.Failed(it.userFacingMessage("설정을 불러오지 못했어요")))
}
}
}

Expand Down
Loading