fix(creator): 팬Talk 답글 응답을 반영한다
This commit is contained in:
@@ -6,7 +6,6 @@ final class CreatorChannelReplyDetailViewModel: ObservableObject {
|
||||
private let communityRepository = CreatorCommunityRepository()
|
||||
private let v2CommunityRepository = CreatorChannelCommunityRepository()
|
||||
private let explorerRepository = ExplorerRepository()
|
||||
private let fanTalkRepository = CreatorChannelFanTalkRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
private var context: CreatorChannelReplyDetailContext?
|
||||
private var onFanTalkRefresh: (() -> Void)?
|
||||
@@ -15,7 +14,6 @@ final class CreatorChannelReplyDetailViewModel: ObservableObject {
|
||||
private let communityReplyPageSize = 20
|
||||
private var communityReplyTotalCount = 0
|
||||
private var isCommunityReplyLast = false
|
||||
private let fanTalkReplyPageSize = 20
|
||||
|
||||
@Published var replyText = ""
|
||||
@Published var parentItem: CreatorChannelReplyDetailDisplayItem?
|
||||
@@ -317,49 +315,7 @@ final class CreatorChannelReplyDetailViewModel: ObservableObject {
|
||||
self.applyFailureState()
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
self?.handleFanTalkMutationResponse(response)
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
|
||||
private func fetchFanTalkReplies(page: Int = 0) {
|
||||
guard case .fanTalk(let creatorId, let parentFanTalk) = context else { return }
|
||||
|
||||
fanTalkRepository.getFanTalks(creatorId: creatorId, page: page, size: fanTalkReplyPageSize)
|
||||
.sink { [weak self] result in
|
||||
guard let self else { return }
|
||||
if case .failure(let error) = result {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.applyFailureState()
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self else { return }
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(ApiResponse<CreatorChannelFanTalkTabResponse>.self, from: response.data)
|
||||
if let data = decoded.data, decoded.success {
|
||||
if let fanTalk = data.fanTalks.first(where: { $0.fanTalkId == parentFanTalk.fanTalkId }) {
|
||||
self.isLoading = false
|
||||
self.replies = fanTalk.latestCreatorReply.map {
|
||||
CreatorChannelReplyDetailDisplayItem(fanTalkReply: $0, creatorId: creatorId)
|
||||
}.map { [$0] } ?? []
|
||||
} else if data.hasNext {
|
||||
self.fetchFanTalkReplies(page: page + 1)
|
||||
} else {
|
||||
self.isLoading = false
|
||||
}
|
||||
} else {
|
||||
self.isLoading = false
|
||||
self.errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.isLoading = false
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
self?.handleFanTalkDeleteResponse(response)
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
@@ -388,11 +344,9 @@ final class CreatorChannelReplyDetailViewModel: ObservableObject {
|
||||
isLoading = false
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(ApiResponseWithoutData.self, from: response.data)
|
||||
if decoded.success {
|
||||
applyLocalSuccessState()
|
||||
onFanTalkRefresh?()
|
||||
fetchFanTalkReplies()
|
||||
let decoded = try JSONDecoder().decode(ApiResponse<CreatorChannelFanTalkReplyResponse>.self, from: response.data)
|
||||
if let data = decoded.data, decoded.success {
|
||||
applyFanTalkReply(data)
|
||||
} else {
|
||||
errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
isShowPopup = true
|
||||
@@ -404,6 +358,41 @@ final class CreatorChannelReplyDetailViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
private func handleFanTalkDeleteResponse(_ response: Moya.Response) {
|
||||
isLoading = false
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(ApiResponseWithoutData.self, from: response.data)
|
||||
if decoded.success {
|
||||
applyLocalSuccessState()
|
||||
onFanTalkRefresh?()
|
||||
} else {
|
||||
errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
errorMessage = I18n.Common.commonError
|
||||
isShowPopup = true
|
||||
}
|
||||
}
|
||||
|
||||
private func applyFanTalkReply(_ response: CreatorChannelFanTalkReplyResponse) {
|
||||
let item = CreatorChannelReplyDetailDisplayItem(fanTalkReply: response, creatorId: contextCreatorId)
|
||||
|
||||
if let editingItem,
|
||||
let index = replies.firstIndex(where: { $0.id == editingItem.id && $0.source == editingItem.source }) {
|
||||
replies[index] = item
|
||||
} else {
|
||||
replies = [item]
|
||||
}
|
||||
|
||||
replyText = ""
|
||||
editingItem = nil
|
||||
deletingItem = nil
|
||||
onFanTalkRefresh?()
|
||||
}
|
||||
|
||||
|
||||
private func applyLocalSuccessState() {
|
||||
let trimmedReplyText = replyText.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
Reference in New Issue
Block a user