feat(creator): 대화하기 채팅방 진입을 연결한다

This commit is contained in:
Yu Sung
2026-07-03 18:57:17 +09:00
parent 2b9018f9cb
commit b84098b15e
4 changed files with 60 additions and 5 deletions

View File

@@ -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