573 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			573 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  UserProfileViewModel.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 2023/08/11.
 | 
						|
//
 | 
						|
 | 
						|
import Foundation
 | 
						|
import Combine
 | 
						|
 | 
						|
final class UserProfileViewModel: ObservableObject {
 | 
						|
    
 | 
						|
    private var repository = ExplorerRepository()
 | 
						|
    private let liveRepository = LiveRepository()
 | 
						|
    private let reportRepository = ReportRepository()
 | 
						|
    private let userRepository = UserRepository()
 | 
						|
    private var subscription = Set<AnyCancellable>()
 | 
						|
    
 | 
						|
    @Published var errorMessage = ""
 | 
						|
    @Published var isShowPopup = false
 | 
						|
    @Published var isLoading = false
 | 
						|
    
 | 
						|
    @Published var paymentDialogTitle = ""
 | 
						|
    @Published var paymentDialogDesc = ""
 | 
						|
    @Published var paymentDialogDesc2 = ""
 | 
						|
    @Published var isShowPaymentDialog = false
 | 
						|
    @Published var paymentDialogConfirmAction = {}
 | 
						|
    @Published var paymentDialogConfirmTitle = ""
 | 
						|
    
 | 
						|
    @Published var secretOrPasswordDialogCan = 0
 | 
						|
    
 | 
						|
    @Published var passwordDialogConfirmAction: (String) -> Void = { _ in }
 | 
						|
    @Published var isShowPasswordDialog = false
 | 
						|
    
 | 
						|
    @Published var navigationTitle = "채널"
 | 
						|
    
 | 
						|
    @Published private(set) var creatorProfile: GetCreatorProfileResponse?
 | 
						|
    @Published private(set) var communityPostList = [GetCommunityPostListResponse]()
 | 
						|
    
 | 
						|
    @Published var isShowShareView = false
 | 
						|
    @Published var shareMessage = ""
 | 
						|
    
 | 
						|
    @Published var isShowReportMenu = false
 | 
						|
    @Published var isShowUesrBlockConfirm = false
 | 
						|
    @Published var isShowUesrReportView = false
 | 
						|
    @Published var isShowProfileReportConfirm = false
 | 
						|
    
 | 
						|
    @Published var cheersId = 0
 | 
						|
    @Published var isShowCheersReportView = false
 | 
						|
    @Published var isShowCheersDeleteView = false
 | 
						|
    
 | 
						|
    @Published var liveStartDate: String? = nil
 | 
						|
    @Published var nowDate: String? = nil
 | 
						|
    
 | 
						|
    let paymentDialogCancelTitle = "취소"
 | 
						|
    
 | 
						|
    func getCreatorProfile(userId: Int) {
 | 
						|
        creatorProfile = nil
 | 
						|
        isLoading = true
 | 
						|
        
 | 
						|
        repository.getCreatorProfile(id: userId)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponse<GetCreatorProfileResponse>.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if let data = decoded.data, decoded.success {
 | 
						|
                        self.creatorProfile = data
 | 
						|
                        self.navigationTitle = "\(data.creator.nickname)님의 채널"
 | 
						|
                        
 | 
						|
                        self.communityPostList.removeAll()
 | 
						|
                        self.communityPostList.append(contentsOf: data.communityPostList)
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
                
 | 
						|
                self.isLoading = false
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func hidePaymentPopup() {
 | 
						|
        isShowPaymentDialog = false
 | 
						|
        isShowPasswordDialog = false
 | 
						|
        
 | 
						|
        paymentDialogTitle = ""
 | 
						|
        paymentDialogDesc = ""
 | 
						|
        paymentDialogConfirmAction = {}
 | 
						|
        
 | 
						|
        secretOrPasswordDialogCan = 0
 | 
						|
        passwordDialogConfirmAction = { _ in }
 | 
						|
    }
 | 
						|
    
 | 
						|
    func reservationLiveRoom(roomId: Int) {
 | 
						|
        getRoomDetail(roomId: roomId) { [unowned self] in
 | 
						|
            if ($0.manager.id == UserDefaults.int(forKey: .userId)) {
 | 
						|
                self.errorMessage = "내가 만든 라이브는 예약할 수 없습니다."
 | 
						|
                self.isShowPopup = true
 | 
						|
            } else {
 | 
						|
                if $0.isPrivateRoom {
 | 
						|
                    self.passwordDialogConfirmAction = { password in
 | 
						|
                        self.reservation(roomId: roomId, password: password)
 | 
						|
                    }
 | 
						|
                    self.isShowPasswordDialog = true
 | 
						|
                } else {
 | 
						|
                    if ($0.price == 0 || $0.isPaid) {
 | 
						|
                        self.reservation(roomId: roomId)
 | 
						|
                    } else {
 | 
						|
                        self.paymentDialogTitle = "\($0.price)캔으로 예약"
 | 
						|
                        self.paymentDialogDesc = "'\($0.title)' 라이브에 참여하기 위해 결제합니다."
 | 
						|
                        self.paymentDialogConfirmTitle = "결제 후 예약하기"
 | 
						|
                        self.paymentDialogConfirmAction = { [unowned self] in
 | 
						|
                            hidePaymentPopup()
 | 
						|
                            reservation(roomId: roomId)
 | 
						|
                        }
 | 
						|
                        self.isShowPaymentDialog = true
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    private func reservation(roomId: Int, password: String? = nil) {
 | 
						|
        isLoading = true
 | 
						|
        let request = MakeLiveReservationRequest(roomId: roomId, password: password)
 | 
						|
        liveRepository.makeReservation(request: request)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                self.isLoading = false
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponse<MakeLiveReservationResponse>.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if let response = decoded.data, decoded.success {
 | 
						|
                        AppState.shared.setAppStep(step: .liveReservationComplete(response: response))
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    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 {
 | 
						|
                        let fromFormatter = DateFormatter()
 | 
						|
                        fromFormatter.dateFormat = "yyyy.MM.dd EEE hh:mm a"
 | 
						|
                        fromFormatter.locale = Locale(identifier: "en_US_POSIX")
 | 
						|
                        let beginDate = fromFormatter.date(from: $0.beginDateTime)!
 | 
						|
                        let now = Date()
 | 
						|
                        
 | 
						|
                        let timeInterval = now.timeIntervalSince(beginDate)
 | 
						|
                        let hours = Int(timeInterval / 3600)
 | 
						|
                        let minutes = Int((timeInterval.truncatingRemainder(dividingBy: 3600)) / 60)
 | 
						|
                        
 | 
						|
                        if hours >= 1 {
 | 
						|
                            self.liveStartDate = beginDate.convertDateFormat(dateFormat: "yyyy-MM-dd, HH:mm")
 | 
						|
                            self.nowDate = now.convertDateFormat(dateFormat: "yyyy-MM-dd, HH:mm")
 | 
						|
                            self.paymentDialogDesc2 = "라이브를 시작한 지 \(hours)시간 \(minutes)분이 지났습니다. 라이브에 입장 후 30분 이내에 라이브가 종료될 수도 있습니다."
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        self.paymentDialogTitle = "유료 라이브 입장"
 | 
						|
                        self.paymentDialogDesc = "\($0.price)캔을 차감하고\n라이브에 입장 하시겠습니까?"
 | 
						|
                        self.paymentDialogConfirmTitle = "결제 후 참여하기"
 | 
						|
                        self.paymentDialogConfirmAction = { [unowned self] in
 | 
						|
                            hidePaymentPopup()
 | 
						|
                            self.enterRoom(roomId: roomId)
 | 
						|
                        }
 | 
						|
                        self.isShowPaymentDialog = true
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    func enterRoom(roomId: Int, onSuccess: (() -> Void)? = nil, password: String? = nil) {
 | 
						|
        isLoading = true
 | 
						|
        let request = EnterOrQuitLiveRoomRequest(roomId: roomId, password: password)
 | 
						|
        liveRepository.enterRoom(request: request)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                self.isLoading = false
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if decoded.success {
 | 
						|
                        AppState.shared.roomId = roomId
 | 
						|
                        
 | 
						|
                        if let onSuccess = onSuccess {
 | 
						|
                            onSuccess()
 | 
						|
                        } else {
 | 
						|
                            if roomId > 0 {
 | 
						|
                                AppState.shared.isShowPlayer = true
 | 
						|
                                AppState.shared.setAppStep(step: .main)
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "라이브에 입장하지 못했습니다.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "라이브에 입장하지 못했습니다.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func creatorFollow(follow: Bool = true, notify: Bool = true) {
 | 
						|
        if let creator = creatorProfile {
 | 
						|
            isLoading = true
 | 
						|
            
 | 
						|
            userRepository.creatorFollow(creatorId: creator.creator.creatorId, follow: follow, notify: notify)
 | 
						|
                .sink { result in
 | 
						|
                    switch result {
 | 
						|
                    case .finished:
 | 
						|
                        DEBUG_LOG("finish")
 | 
						|
                    case .failure(let error):
 | 
						|
                        ERROR_LOG(error.localizedDescription)
 | 
						|
                    }
 | 
						|
                } receiveValue: { [unowned self] response in
 | 
						|
                    self.isLoading = false
 | 
						|
                    let responseData = response.data
 | 
						|
                    
 | 
						|
                    do {
 | 
						|
                        let jsonDecoder = JSONDecoder()
 | 
						|
                        let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                        
 | 
						|
                        if decoded.success {
 | 
						|
                            self.getCreatorProfile(userId: creator.creator.creatorId)
 | 
						|
                        } else {
 | 
						|
                            if let message = decoded.message {
 | 
						|
                                self.errorMessage = message
 | 
						|
                            } else {
 | 
						|
                                self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                            }
 | 
						|
                            
 | 
						|
                            self.isShowPopup = true
 | 
						|
                        }
 | 
						|
                    } catch {
 | 
						|
                        self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                .store(in: &subscription)
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    func creatorUnFollow() {
 | 
						|
        if let creator = creatorProfile {
 | 
						|
            isLoading = true
 | 
						|
            
 | 
						|
            userRepository.creatorUnFollow(creatorId: creator.creator.creatorId)
 | 
						|
                .sink { result in
 | 
						|
                    switch result {
 | 
						|
                    case .finished:
 | 
						|
                        DEBUG_LOG("finish")
 | 
						|
                    case .failure(let error):
 | 
						|
                        ERROR_LOG(error.localizedDescription)
 | 
						|
                    }
 | 
						|
                } receiveValue: { [unowned self] response in
 | 
						|
                    self.isLoading = false
 | 
						|
                    let responseData = response.data
 | 
						|
                    
 | 
						|
                    do {
 | 
						|
                        let jsonDecoder = JSONDecoder()
 | 
						|
                        let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                        
 | 
						|
                        if decoded.success {
 | 
						|
                            self.getCreatorProfile(userId: creator.creator.creatorId)
 | 
						|
                        } else {
 | 
						|
                            if let message = decoded.message {
 | 
						|
                                self.errorMessage = message
 | 
						|
                            } else {
 | 
						|
                                self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                            }
 | 
						|
                            
 | 
						|
                            self.isShowPopup = true
 | 
						|
                        }
 | 
						|
                    } catch {
 | 
						|
                        self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                .store(in: &subscription)
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    private func getRoomDetail(roomId: Int, onSuccess: @escaping (GetRoomDetailResponse) -> Void) {
 | 
						|
        isLoading = true
 | 
						|
        liveRepository.getRoomDetail(roomId: roomId)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { response in
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponse<GetRoomDetailResponse>.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if let data = decoded.data, decoded.success {
 | 
						|
                        onSuccess(data)
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "라이브 정보를 가져오지 못했습니다.\n다시 시도해 주세요."
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "라이브 정보를 가져오지 못했습니다.\n다시 시도해 주세요."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
                
 | 
						|
                self.isLoading = false
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func shareChannel(userId: Int, nickname: String, profileImage: String) {
 | 
						|
        isLoading = true
 | 
						|
        
 | 
						|
        let params = [
 | 
						|
            "af_dp": "voiceon://",
 | 
						|
            "deep_link_value": "channel",
 | 
						|
            "deep_link_sub5": "\(userId)"
 | 
						|
        ]
 | 
						|
        
 | 
						|
        if let shareUrl = createOneLinkUrlWithURLComponents(params: params) {
 | 
						|
            self.shareMessage = "보이스온 \(nickname)님의 채널입니다.\n\(shareUrl)"
 | 
						|
            self.isShowShareView = true
 | 
						|
        } else {
 | 
						|
            self.errorMessage = "공유링크를 생성하지 못했습니다.\n다시 시도해 주세요."
 | 
						|
            self.isShowPopup = true
 | 
						|
        }
 | 
						|
        
 | 
						|
        self.isLoading = false
 | 
						|
    }
 | 
						|
    
 | 
						|
    func userBlock(userId: Int) {
 | 
						|
        isLoading = true
 | 
						|
        userRepository.memberBlock(userId: userId)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                self.isLoading = false
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if decoded.success {
 | 
						|
                        getCreatorProfile(userId: userId)
 | 
						|
                        self.errorMessage = "차단하였습니다."
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    self.isShowPopup = true
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func userUnBlock(userId: Int) {
 | 
						|
        isLoading = true
 | 
						|
        userRepository.memberUnBlock(userId: userId)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                self.isLoading = false
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if decoded.success {
 | 
						|
                        getCreatorProfile(userId: userId)
 | 
						|
                        self.errorMessage = "차단이 해제 되었습니다."
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    self.isShowPopup = true
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func report(type: ReportType, userId: Int? = nil, reason: String = "프로필 신고") {
 | 
						|
        isLoading = true
 | 
						|
        
 | 
						|
        let request = ReportRequest(type: type, reason: reason, reportedMemberId: userId, cheersId: cheersId > 0 && type == .CHEERS ? cheersId : nil, audioContentId: nil)
 | 
						|
        reportRepository.report(request: request)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                self.isLoading = false
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                self.cheersId = 0
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if let message = decoded.message {
 | 
						|
                        self.errorMessage = message
 | 
						|
                    } else {
 | 
						|
                        self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    self.isShowPopup = true
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func deleteCheers(creatorId: Int) {
 | 
						|
        isLoading = true
 | 
						|
        
 | 
						|
        repository.modifyCheers(cheersId: cheersId, content: nil, isActive: false)
 | 
						|
            .sink { result in
 | 
						|
                switch result {
 | 
						|
                case .finished:
 | 
						|
                    DEBUG_LOG("finish")
 | 
						|
                case .failure(let error):
 | 
						|
                    ERROR_LOG(error.localizedDescription)
 | 
						|
                }
 | 
						|
            } receiveValue: { [unowned self] response in
 | 
						|
                self.cheersId = 0
 | 
						|
                self.isLoading = false
 | 
						|
                let responseData = response.data
 | 
						|
                
 | 
						|
                do {
 | 
						|
                    let jsonDecoder = JSONDecoder()
 | 
						|
                    let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
 | 
						|
                    
 | 
						|
                    if decoded.success {
 | 
						|
                        self.getCreatorProfile(userId: creatorId)
 | 
						|
                    } else {
 | 
						|
                        if let message = decoded.message {
 | 
						|
                            self.errorMessage = message
 | 
						|
                        } else {
 | 
						|
                            self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        self.isShowPopup = true
 | 
						|
                    }
 | 
						|
                } catch {
 | 
						|
                    self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
						|
                    self.isShowPopup = true
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .store(in: &subscription)
 | 
						|
    }
 | 
						|
}
 |