라이브방

- 하트바 위치 수정 : 채팅 -> 공지 밑
This commit is contained in:
Yu Sung 2024-10-27 18:05:45 +09:00
parent 37aa6d13de
commit fed781521d
5 changed files with 40 additions and 18 deletions

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
enum LiveRoomChatType: String { enum LiveRoomChatType: String {
case CHAT, DONATION, JOIN, ROULETTE_DONATION, HEART case CHAT, DONATION, JOIN, ROULETTE_DONATION
} }
protocol LiveRoomChat { protocol LiveRoomChat {
@ -48,9 +48,3 @@ struct LiveRoomJoinChat: LiveRoomChat {
var type: LiveRoomChatType = .JOIN var type: LiveRoomChatType = .JOIN
} }
struct LiveRoomHeartDonationChat: LiveRoomChat {
let nickname: String
var type: LiveRoomChatType = .HEART
}

View File

@ -9,7 +9,7 @@ import SwiftUI
struct LiveRoomHeartDonationChatItemView: View { struct LiveRoomHeartDonationChatItemView: View {
let chatMessage: LiveRoomHeartDonationChat let nickname: String
var body: some View { var body: some View {
HStack(spacing: 0) { HStack(spacing: 0) {
@ -17,7 +17,7 @@ struct LiveRoomHeartDonationChatItemView: View {
.font(.system(size: 12)) .font(.system(size: 12))
.foregroundColor(Color.gray11) .foregroundColor(Color.gray11)
Text(chatMessage.nickname) Text(nickname)
.font(.system(size: 12, weight: .bold)) .font(.system(size: 12, weight: .bold))
.foregroundColor(Color(hex: "ec3aa6")) .foregroundColor(Color(hex: "ec3aa6"))
@ -26,13 +26,12 @@ struct LiveRoomHeartDonationChatItemView: View {
.foregroundColor(Color.gray11) .foregroundColor(Color.gray11)
} }
.padding(.vertical, 6.7) .padding(.vertical, 6.7)
.frame(width: screenSize().width - 86) .frame(maxWidth: .infinity)
.background(Color.white.opacity(0.7)) .background(Color.white.opacity(0.7))
.cornerRadius(4.7) .cornerRadius(4.7)
.padding(.leading, 20)
} }
} }
#Preview { #Preview {
LiveRoomHeartDonationChatItemView(chatMessage: LiveRoomHeartDonationChat(nickname: "닉네임")) LiveRoomHeartDonationChatItemView(nickname: "닉네임")
} }

View File

@ -186,6 +186,15 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
} }
} }
@Published var heartNickname: String? = nil {
didSet {
if heartNickname != nil {
showNextHeartMessage()
}
}
}
@Published var heartNicknameList = [String]()
private var menuId = 0 private var menuId = 0
@Published var menu = "" @Published var menu = ""
@Published var menuList = [GetMenuPresetResponse]() @Published var menuList = [GetMenuPresetResponse]()
@ -1881,7 +1890,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
completion: { [unowned self] errorCode in completion: { [unowned self] errorCode in
if errorCode == .errorOk { if errorCode == .errorOk {
let (nickname, _) = self.getUserNicknameAndProfileUrl(accountId: UserDefaults.int(forKey: .userId)) let (nickname, _) = self.getUserNicknameAndProfileUrl(accountId: UserDefaults.int(forKey: .userId))
self.messages.append(LiveRoomHeartDonationChat(nickname: nickname)) self.addHeartMessage(nickname: nickname)
totalHeartCount += 1 totalHeartCount += 1
addHeart() addHeart()
@ -1963,6 +1972,25 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
} }
} }
private func addHeartMessage(nickname: String) {
if heartNickname != nil {
self.heartNicknameList.append(nickname)
} else {
self.heartNickname = nickname
}
}
private func showNextHeartMessage() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if let nextHeartNickname = self.heartNicknameList.first {
self.heartNickname = nextHeartNickname
self.heartNicknameList.removeFirst()
} else {
self.heartNickname = nil
}
}
}
func startHeartTimer() { func startHeartTimer() {
if heartTimer == nil { if heartTimer == nil {
let timer = DispatchSource.makeTimerSource(queue: DispatchQueue.main) let timer = DispatchSource.makeTimerSource(queue: DispatchQueue.main)
@ -2193,7 +2221,7 @@ extension LiveRoomViewModel: AgoraRtmChannelDelegate {
} else if decoded.type == .EDIT_ROOM_INFO || decoded.type == .SET_MANAGER { } else if decoded.type == .EDIT_ROOM_INFO || decoded.type == .SET_MANAGER {
self.getRoomInfo() self.getRoomInfo()
} else if decoded.type == .HEART_DONATION { } else if decoded.type == .HEART_DONATION {
self.messages.append(LiveRoomHeartDonationChat(nickname: nickname)) self.addHeartMessage(nickname: nickname)
self.totalHeartCount += decoded.can self.totalHeartCount += decoded.can
self.addHeart() self.addHeart()
} }

View File

@ -28,10 +28,6 @@ struct LiveRoomChatView: View {
let chatMessage = messages[index] as! LiveRoomJoinChat let chatMessage = messages[index] as! LiveRoomJoinChat
LiveRoomJoinChatItemView(chatMessage: chatMessage) LiveRoomJoinChatItemView(chatMessage: chatMessage)
case LiveRoomChatType.HEART:
let chatMessage = messages[index] as! LiveRoomHeartDonationChat
LiveRoomHeartDonationChatItemView(chatMessage: chatMessage)
default: default:
let chatMessage = messages[index] as! LiveRoomNormalChat let chatMessage = messages[index] as! LiveRoomNormalChat
LiveRoomChatItemView( LiveRoomChatItemView(

View File

@ -289,6 +289,11 @@ struct LiveRoomViewV2: View {
} }
} }
if let heartNickname = viewModel.heartNickname {
LiveRoomHeartDonationChatItemView(nickname: heartNickname)
.padding(.top, 16)
}
if viewModel.isShowNotice { if viewModel.isShowNotice {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
Image("ic_notice_triangle") Image("ic_notice_triangle")