Skip to content
Merged
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 @@ -97,39 +97,51 @@ extension SandBeachFeature {
Log.error(error)
}
})

return .run { send in
async let _ = authClient.checkUpdateVersion()
let userProfileStatus = try await profileClient.fetchUserProfileSelect()
let userBottleInfo = try await bottleClient.fetchUserBottleInfo()
async let versionCheckTask: Void = authClient.checkUpdateVersion()
async let userProfileStatusTask = profileClient.fetchUserProfileSelect()
async let userBottleInfoTask = bottleClient.fetchUserBottleInfo()
async let bottlesStorageListTask = bottleClient.fetchBottleStorageList()

let (_, userProfileStatus, userBottleInfo, bottlesStorageList) = try await (
versionCheckTask,
userProfileStatusTask,
userBottleInfoTask,
bottlesStorageListTask
)

let newBottlesCount = userBottleInfo.randomBottleCount
let bottlesStorageList = try await bottleClient.fetchBottleStorageList()
let activeBottlesCount = bottlesStorageList.pingPongBottles
.filter { $0.lastStatus != .conversationStopped && $0.lastStatus != .contactSharedByMeOnly }.count
let nextBottleLeftHours = userBottleInfo.nextBottlLeftHours

if newBottlesCount > 0 {
if userProfileStatus == .empty || userProfileStatus == .doneIntroduction {
await send(.userStateFetchCompleted(
userState: .hasNewBottle(bottleCount: newBottlesCount),
isDisableButton: false))
userState: .noIntroduction,
isDisableButton: true))
return
}

if activeBottlesCount > 0 {
if userProfileStatus == .doneProfileImage {
await send(.userStateFetchCompleted(
userState: .hasActiveBottle(bottleCount: activeBottlesCount),
userState: .noBottle(time: nextBottleLeftHours ?? 0),
isDisableButton: false))
return
}

if userProfileStatus == .empty || userProfileStatus == .doneIntroduction {
if newBottlesCount > 0 {
await send(.userStateFetchCompleted(
userState: .noIntroduction,
isDisableButton: true))
} else if userProfileStatus == .doneProfileImage {
userState: .hasNewBottle(bottleCount: newBottlesCount),
isDisableButton: false))
return
}

if activeBottlesCount > 0 {
await send(.userStateFetchCompleted(
userState: .noBottle(time: nextBottleLeftHours ?? 0),
userState: .hasActiveBottle(bottleCount: activeBottlesCount),
isDisableButton: false))
return
}
} catch: { error, send in
// TODO: 에러 핸들링
Expand Down