diff --git a/SodaLive/Sources/Live/LiveViewModel.swift b/SodaLive/Sources/Live/LiveViewModel.swift index baa5e2a..f1896c2 100644 --- a/SodaLive/Sources/Live/LiveViewModel.swift +++ b/SodaLive/Sources/Live/LiveViewModel.swift @@ -404,6 +404,56 @@ final class LiveViewModel: ObservableObject { } } + func enterLiveRoom(roomId: Int) { + getRoomDetail(roomId: roomId) { + if let _ = $0.channelName { + if $0.manager.id == UserDefaults.int(forKey: .userId) { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { + self.enterRoom(roomId: roomId) + } + } else if ($0.price == 0 || $0.isPaid) { + if $0.isPrivateRoom { + self.passwordDialogConfirmAction = { password in + self.enterRoom(roomId: roomId, password: password) + } + self.isShowPasswordDialog = true + } else { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { + self.enterRoom(roomId: roomId) + } + } + } else { + if $0.isPrivateRoom { + self.secretOrPasswordDialogCan = $0.price + self.passwordDialogConfirmAction = { password in + self.enterRoom(roomId: roomId, password: password) + } + self.isShowPasswordDialog = true + } else { + self.paymentDialogTitle = "\($0.price)캔으로 입장" + self.paymentDialogDesc = "'\($0.title)' 라이브에 참여하기 위해 결제합니다." + self.paymentDialogConfirmTitle = "결제 후 참여하기" + self.paymentDialogConfirmAction = { [unowned self] in + hidePopup() + self.enterRoom(roomId: roomId) + } + self.isShowPaymentDialog = true + } + } + } else { + AppState.shared.setAppStep( + step: .liveDetail( + roomId: roomId, + onClickParticipant: {}, + onClickReservation: { self.reservationLiveRoom(roomId: roomId) }, + onClickStart: { self.startLive(roomId: roomId) }, + onClickCancel: { self.getSummary() } + ) + ) + } + } + } + private func getRoomDetail(roomId: Int, onSuccess: @escaping (GetRoomDetailResponse) -> Void) { isLoading = true repository.getRoomDetail(roomId: roomId) diff --git a/SodaLive/Sources/Main/Home/HomeView.swift b/SodaLive/Sources/Main/Home/HomeView.swift index b9cd1b0..71986ad 100644 --- a/SodaLive/Sources/Main/Home/HomeView.swift +++ b/SodaLive/Sources/Main/Home/HomeView.swift @@ -124,6 +124,25 @@ struct HomeView: View { NotificationSettingsDialog() } + if liveViewModel.isShowPaymentDialog { + SodaDialog( + title: liveViewModel.paymentDialogTitle, + desc: liveViewModel.paymentDialogDesc, + confirmButtonTitle: liveViewModel.paymentDialogConfirmTitle, + confirmButtonAction: liveViewModel.paymentDialogConfirmAction, + cancelButtonTitle: liveViewModel.paymentDialogCancelTitle, + cancelButtonAction: liveViewModel.hidePopup + ) + } + + if liveViewModel.isShowPasswordDialog { + LiveRoomPasswordDialog( + isShowing: $liveViewModel.isShowPasswordDialog, + can: liveViewModel.secretOrPasswordDialogCan, + confirmAction: liveViewModel.passwordDialogConfirmAction + ) + } + if let eventItem = appState.eventPopup { VStack(spacing: 0) { Spacer() @@ -148,7 +167,7 @@ struct HomeView: View { appState.setAppStep(step: .main) if value > 0 { - liveViewModel.enterRoom(roomId: value) + liveViewModel.enterLiveRoom(roomId: value) } } } @@ -182,7 +201,7 @@ struct HomeView: View { .onAppear { if appState.pushRoomId > 0 { DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { - liveViewModel.enterRoom(roomId: appState.pushRoomId) + liveViewModel.enterLiveRoom(roomId: appState.pushRoomId) } } else if appState.pushChannelId > 0 { DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {