채금 기능 추가
This commit is contained in:
@@ -118,11 +118,22 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
@Published var isShowUesrBlockConfirm = false
|
||||
@Published var isShowUesrReportView = false
|
||||
@Published var isShowProfileReportConfirm = false
|
||||
@Published var isShowNoChattingConfirm = false
|
||||
|
||||
@Published var reportUserId = 0
|
||||
@Published var reportUserNickname = ""
|
||||
@Published var reportUserIsBlocked = false
|
||||
|
||||
@Published var noChattingUserId = 0
|
||||
@Published var noChattingUserNickname = ""
|
||||
@Published var noChattingUserProfileUrl = ""
|
||||
|
||||
private let noChattingTime = 180
|
||||
@Published var isNoChatting = false
|
||||
@Published var remainingNoChattingTime = 0
|
||||
|
||||
var timer: DispatchSourceTimer?
|
||||
|
||||
func setOriginOffset(_ offset: CGFloat) {
|
||||
guard !isCheckedOriginOffset else { return }
|
||||
self.originOffset = offset
|
||||
@@ -146,6 +157,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
}
|
||||
|
||||
func agoraConnectSuccess(isManager: Bool) {
|
||||
self.isLoading = false
|
||||
if isManager {
|
||||
role = .SPEAKER
|
||||
} else {
|
||||
@@ -153,9 +165,14 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
}
|
||||
|
||||
DEBUG_LOG("agoraConnectSuccess")
|
||||
|
||||
if containNoChatRoom() {
|
||||
startNoChatting()
|
||||
}
|
||||
}
|
||||
|
||||
func agoraConnectFail() {
|
||||
self.isLoading = false
|
||||
DEBUG_LOG("agoraConnectFail")
|
||||
AppState.shared.roomId = 0
|
||||
AppState.shared.isShowPlayer = false
|
||||
@@ -226,6 +243,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.liveRoomInfo = data
|
||||
self.isLoading = true
|
||||
self.agora.joinChannel(
|
||||
roomInfo: data,
|
||||
rtmChannelDelegate: self,
|
||||
@@ -279,7 +297,10 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
|
||||
func sendMessage() {
|
||||
DispatchQueue.main.async {[unowned self] in
|
||||
if chatMessage.count > 0 {
|
||||
if isNoChatting {
|
||||
self.popupContent = "\(remainingNoChattingTime)초 동안 채팅하실 수 없습니다"
|
||||
self.isShowPopup = true
|
||||
} else if chatMessage.count > 0 {
|
||||
agora.sendMessageToGroup(textMessage: chatMessage, completion: { [unowned self] errorCode in
|
||||
if errorCode == .errorOk {
|
||||
let (nickname, profileUrl) = self.getUserNicknameAndProfileUrl(accountId: UserDefaults.int(forKey: .userId))
|
||||
@@ -1078,6 +1099,25 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
)
|
||||
}
|
||||
|
||||
func setNoChatting() {
|
||||
agora.sendMessageToPeer(
|
||||
peerId: String(noChattingUserId),
|
||||
rawMessage: LiveRoomRequestType.NO_CHATTING.rawValue.data(using: .utf8)!,
|
||||
completion: { [unowned self] errorCode in
|
||||
if errorCode == .ok {
|
||||
self.popupContent = "\(noChattingUserNickname)님을 3분간 채팅금지를 하였습니다."
|
||||
self.isShowPopup = true
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
||||
self.noChattingUserId = 0
|
||||
self.noChattingUserNickname = ""
|
||||
self.noChattingUserProfileUrl = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private func setManagerMessage() {
|
||||
let setManagerMessage = LiveRoomChatRawMessage(
|
||||
type: .SET_MANAGER,
|
||||
@@ -1209,6 +1249,76 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func containNoChatRoom() -> Bool {
|
||||
let noChatRoomList = getNoChatRoomListFromUserDefaults()
|
||||
if let _ = noChatRoomList.firstIndex(of: liveRoomInfo!.roomId) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private func startNoChatting() {
|
||||
isNoChatting = true
|
||||
popupContent = "\(self.getUserNicknameAndProfileUrl(accountId: liveRoomInfo!.creatorId).nickname)님이 3분간 채팅을 금지하였습니다."
|
||||
isShowPopup = true
|
||||
|
||||
startCountDown()
|
||||
}
|
||||
|
||||
private func startCountDown() {
|
||||
// 1초마다 타이머를 실행
|
||||
let queue = DispatchQueue.global(qos: .background)
|
||||
timer = DispatchSource.makeTimerSource(queue: queue)
|
||||
timer?.schedule(deadline: .now(), repeating: 1.0)
|
||||
timer?.setEventHandler { [unowned self] in
|
||||
DispatchQueue.main.async {
|
||||
self.remainingNoChattingTime -= 1
|
||||
|
||||
if self.remainingNoChattingTime <= 0 {
|
||||
self.isNoChatting = false
|
||||
self.timer?.cancel()
|
||||
self.remainingNoChattingTime = self.noChattingTime
|
||||
self.removeNoChatRoom()
|
||||
self.popupContent = "채팅금지가 해제되었습니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
}
|
||||
timer?.resume()
|
||||
}
|
||||
|
||||
private func addNoChatRoom() {
|
||||
var noChatRoomList = getNoChatRoomListFromUserDefaults()
|
||||
noChatRoomList.append(liveRoomInfo!.roomId)
|
||||
saveNoChatRoomListToUserDefaults(noChatRoomList: noChatRoomList)
|
||||
}
|
||||
|
||||
private func removeNoChatRoom() {
|
||||
var noChatRoomList = getNoChatRoomListFromUserDefaults()
|
||||
if let index = noChatRoomList.firstIndex(of: liveRoomInfo!.roomId) {
|
||||
noChatRoomList.remove(at: index)
|
||||
}
|
||||
saveNoChatRoomListToUserDefaults(noChatRoomList: noChatRoomList)
|
||||
}
|
||||
|
||||
private func getNoChatRoomListFromUserDefaults() -> [Int] {
|
||||
if let noChatRoomListData = UserDefaults.data(forKey: .noChatRoomList) {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
if let noChatRoomList = try? jsonDecoder.decode([Int].self, from: noChatRoomListData) {
|
||||
return noChatRoomList
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
private func saveNoChatRoomListToUserDefaults(noChatRoomList: [Int]) {
|
||||
let jsonEncoder = JSONEncoder()
|
||||
if let jsonData = try? jsonEncoder.encode(noChatRoomList) {
|
||||
UserDefaults.set(jsonData, forKey: .noChatRoomList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension LiveRoomViewModel: AgoraRtcEngineDelegate {
|
||||
@@ -1340,6 +1450,13 @@ extension LiveRoomViewModel: AgoraRtmDelegate {
|
||||
}
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
if rawMessageString == LiveRoomRequestType.NO_CHATTING.rawValue {
|
||||
DispatchQueue.main.async {
|
||||
self.addNoChatRoom()
|
||||
self.startNoChatting()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user