feat(creator): 대화하기 채팅방 진입을 연결한다
This commit is contained in:
@@ -121,6 +121,42 @@ final class CreatorChannelViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func createChatRoom(characterId: Int, onSuccess: @escaping (Int) -> Void) {
|
||||
guard characterId > 0 else { return }
|
||||
isLoading = true
|
||||
|
||||
repository.createChatRoom(characterId: characterId)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self?.isLoading = false
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
self?.isLoading = false
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<CreateChatRoomResponse>.self, from: response.data)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
onSuccess(data.chatRoomId)
|
||||
} else {
|
||||
self?.errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
self?.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self?.errorMessage = I18n.Common.commonError
|
||||
self?.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func applyApiFailedPlaceholderState() {
|
||||
response = nil
|
||||
isApiFailedPlaceholderVisible = true
|
||||
|
||||
Reference in New Issue
Block a user