feat(creator): 대화하기 채팅방 진입을 연결한다
This commit is contained in:
@@ -313,7 +313,7 @@ struct CreatorChannelView: View {
|
||||
|
||||
if isKoreanCountry && auth == false {
|
||||
pendingAction = {
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
startChat(characterId: characterId)
|
||||
}
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
@@ -325,7 +325,13 @@ struct CreatorChannelView: View {
|
||||
return
|
||||
}
|
||||
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
startChat(characterId: characterId)
|
||||
}
|
||||
|
||||
private func startChat(characterId: Int) {
|
||||
viewModel.createChatRoom(characterId: characterId) { chatRoomId in
|
||||
AppState.shared.setAppStep(step: .chatRoom(id: chatRoomId))
|
||||
}
|
||||
}
|
||||
|
||||
private func moveToContentSettingsWithGuideToast() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,8 +6,13 @@ import Moya
|
||||
|
||||
final class CreatorChannelHomeRepository {
|
||||
private let api = MoyaProvider<CreatorChannelHomeApi>()
|
||||
private let talkApi = MoyaProvider<TalkApi>()
|
||||
|
||||
func getHome(creatorId: Int) -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getHome(creatorId: creatorId))
|
||||
}
|
||||
|
||||
func createChatRoom(characterId: Int) -> AnyPublisher<Response, MoyaError> {
|
||||
return talkApi.requestPublisher(.createChatRoom(request: CreateChatRoomRequest(characterId: characterId)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user