feat(chat-settings-view): 대화설정
- 배경 이미지 숨김 - 대화 초기화 기능 추가
This commit is contained in:
@@ -11,6 +11,7 @@ import Moya
|
||||
|
||||
final class ChatRoomViewModel: ObservableObject {
|
||||
// MARK: - Published State
|
||||
@Published var isResetting: Bool = false
|
||||
@Published var isLoading: Bool = false
|
||||
@Published var errorMessage: String = ""
|
||||
@Published var isShowPopup = false
|
||||
@@ -36,6 +37,15 @@ final class ChatRoomViewModel: ObservableObject {
|
||||
@Published var isShowImageViewer = false
|
||||
@Published var selectedImageIndex: Int = 0
|
||||
|
||||
@Published var isHideBg = false {
|
||||
didSet {
|
||||
UserDefaults.standard.set(isHideBg, forKey: bgHideKey())
|
||||
}
|
||||
}
|
||||
@Published var isShowingChatSettingsView = false
|
||||
@Published var isShowingChangeBgView = false
|
||||
@Published var isShowingChatResetConfirmDialog = false
|
||||
|
||||
var ownedImageUrls: [String] {
|
||||
return messages
|
||||
.filter { $0.hasAccess }
|
||||
@@ -54,7 +64,6 @@ final class ChatRoomViewModel: ObservableObject {
|
||||
private var timer: Timer?
|
||||
|
||||
// MARK: - Actions
|
||||
@MainActor
|
||||
func sendMessage() {
|
||||
guard !messageText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
||||
return
|
||||
@@ -118,10 +127,10 @@ final class ChatRoomViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func enterRoom(roomId: Int) {
|
||||
isLoading = true
|
||||
self.roomId = roomId
|
||||
self.isHideBg = UserDefaults.standard.bool(forKey: bgHideKey())
|
||||
|
||||
repository.enterChatRoom(
|
||||
roomId: roomId,
|
||||
@@ -291,6 +300,47 @@ final class ChatRoomViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func resetChatRoom() {
|
||||
isResetting = true
|
||||
|
||||
repository.resetChatRoom(roomId: roomId)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
let responseData = response.data
|
||||
self?.isResetting = false
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<CreateChatRoomResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self?.resetData()
|
||||
self?.getMemberInfo()
|
||||
self?.enterRoom(roomId: data.chatRoomId)
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self?.errorMessage = message
|
||||
} else {
|
||||
self?.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self?.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(String(describing: error))
|
||||
self?.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self?.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func showImageViewer(_ imageUrl: String?) {
|
||||
if let imageUrl = imageUrl {
|
||||
selectedImageIndex = ownedImageUrls.firstIndex(of: imageUrl) ?? 0
|
||||
@@ -298,6 +348,30 @@ final class ChatRoomViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
private func resetData() {
|
||||
characterProfileUrl = ""
|
||||
characterName = "Character Name"
|
||||
characterType = .Character
|
||||
chatRoomBgImageUrl = nil
|
||||
roomId = 0
|
||||
|
||||
countdownText = "00:00:00"
|
||||
showQuotaNoticeView = false
|
||||
|
||||
showSendingMessage = false
|
||||
|
||||
messageText = ""
|
||||
messages = []
|
||||
selectedMessage = nil
|
||||
selectedMessageIndex = -1
|
||||
isShowImageViewer = false
|
||||
selectedImageIndex = 0
|
||||
|
||||
isShowingChatSettingsView = false
|
||||
isShowingChangeBgView = false
|
||||
isShowingChatResetConfirmDialog = false
|
||||
}
|
||||
|
||||
private func checkQuotaStatus() {
|
||||
isLoading = true
|
||||
|
||||
@@ -420,4 +494,8 @@ final class ChatRoomViewModel: ObservableObject {
|
||||
private func bgImageIdKey() -> String {
|
||||
return "chat_bg_image_id_room_\(roomId)"
|
||||
}
|
||||
|
||||
private func bgHideKey() -> String {
|
||||
return "chat_bg_hide_room_\(roomId)"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user