68 lines
2.1 KiB
Swift
68 lines
2.1 KiB
Swift
//
|
|
// ChatRoomViewModel.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 9/2/25.
|
|
//
|
|
|
|
import Foundation
|
|
import Combine
|
|
import Moya
|
|
|
|
final class ChatRoomViewModel: ObservableObject {
|
|
// MARK: - Published State
|
|
@Published var isLoading: Bool = false
|
|
@Published var errorMessage: String = ""
|
|
@Published var isShowPopup = false
|
|
|
|
@Published private(set) var characterProfileUrl: String = ""
|
|
@Published private(set) var characterName: String = "Character Name"
|
|
@Published private(set) var characterType: CharacterType = .Character
|
|
|
|
// MARK: - Message State
|
|
@Published var messageText: String = ""
|
|
@Published private(set) var messages: [ServerChatMessage] = [
|
|
ServerChatMessage(
|
|
messageId: 1,
|
|
message: "(만약에) 멈춰 인프피",
|
|
profileImageUrl: "",
|
|
mine: true,
|
|
createdAt: Date().currentTimeMillis(),
|
|
messageType: "text",
|
|
imageUrl: nil,
|
|
price: nil,
|
|
hasAccess: true
|
|
),
|
|
ServerChatMessage(
|
|
messageId: 2,
|
|
message: "(언제부턴가) 너랑 노는게 제일 재밌고\n너랑 이야기 하는게 제일 신나더라,\n앞으로도 그럴 것 같아❤️",
|
|
profileImageUrl: "https://example.com/profile.jpg",
|
|
mine: false,
|
|
createdAt: Date().currentTimeMillis(),
|
|
messageType: "text",
|
|
imageUrl: nil,
|
|
price: nil,
|
|
hasAccess: true
|
|
)
|
|
]
|
|
|
|
// MARK: - Private
|
|
private let userRepository = UserRepository()
|
|
private let repository = ChatRoomRepository()
|
|
private var subscription = Set<AnyCancellable>()
|
|
|
|
// MARK: - Actions
|
|
@MainActor
|
|
func sendMessage() {
|
|
guard !messageText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
|
return
|
|
}
|
|
|
|
let message = messageText.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
messageText = ""
|
|
|
|
// TODO: 실제 메시지 전송 로직 구현
|
|
DEBUG_LOG("메시지 전송: \(message)")
|
|
}
|
|
}
|