From fed781521d37c48bdfb3ef41abcf86492dd768fb Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Sun, 27 Oct 2024 18:05:45 +0900 Subject: [PATCH] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=EB=B0=A9=20-=20?= =?UTF-8?q?=ED=95=98=ED=8A=B8=EB=B0=94=20=EC=9C=84=EC=B9=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20:=20=EC=B1=84=ED=8C=85=20->=20=EA=B3=B5=EC=A7=80=20?= =?UTF-8?q?=EB=B0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Live/Room/Chat/LiveRoomChat.swift | 8 +---- .../LiveRoomHeartDonationChatItemView.swift | 9 +++--- .../Sources/Live/Room/LiveRoomViewModel.swift | 32 +++++++++++++++++-- .../V2/Component/View/LiveRoomChatView.swift | 4 --- .../Sources/Live/Room/V2/LiveRoomViewV2.swift | 5 +++ 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/SodaLive/Sources/Live/Room/Chat/LiveRoomChat.swift b/SodaLive/Sources/Live/Room/Chat/LiveRoomChat.swift index f775496..8af0bcc 100644 --- a/SodaLive/Sources/Live/Room/Chat/LiveRoomChat.swift +++ b/SodaLive/Sources/Live/Room/Chat/LiveRoomChat.swift @@ -8,7 +8,7 @@ import Foundation enum LiveRoomChatType: String { - case CHAT, DONATION, JOIN, ROULETTE_DONATION, HEART + case CHAT, DONATION, JOIN, ROULETTE_DONATION } protocol LiveRoomChat { @@ -48,9 +48,3 @@ struct LiveRoomJoinChat: LiveRoomChat { var type: LiveRoomChatType = .JOIN } - -struct LiveRoomHeartDonationChat: LiveRoomChat { - let nickname: String - - var type: LiveRoomChatType = .HEART -} diff --git a/SodaLive/Sources/Live/Room/Chat/LiveRoomHeartDonationChatItemView.swift b/SodaLive/Sources/Live/Room/Chat/LiveRoomHeartDonationChatItemView.swift index 0bb3936..32f3c7f 100644 --- a/SodaLive/Sources/Live/Room/Chat/LiveRoomHeartDonationChatItemView.swift +++ b/SodaLive/Sources/Live/Room/Chat/LiveRoomHeartDonationChatItemView.swift @@ -9,7 +9,7 @@ import SwiftUI struct LiveRoomHeartDonationChatItemView: View { - let chatMessage: LiveRoomHeartDonationChat + let nickname: String var body: some View { HStack(spacing: 0) { @@ -17,7 +17,7 @@ struct LiveRoomHeartDonationChatItemView: View { .font(.system(size: 12)) .foregroundColor(Color.gray11) - Text(chatMessage.nickname) + Text(nickname) .font(.system(size: 12, weight: .bold)) .foregroundColor(Color(hex: "ec3aa6")) @@ -26,13 +26,12 @@ struct LiveRoomHeartDonationChatItemView: View { .foregroundColor(Color.gray11) } .padding(.vertical, 6.7) - .frame(width: screenSize().width - 86) + .frame(maxWidth: .infinity) .background(Color.white.opacity(0.7)) .cornerRadius(4.7) - .padding(.leading, 20) } } #Preview { - LiveRoomHeartDonationChatItemView(chatMessage: LiveRoomHeartDonationChat(nickname: "닉네임")) + LiveRoomHeartDonationChatItemView(nickname: "닉네임") } diff --git a/SodaLive/Sources/Live/Room/LiveRoomViewModel.swift b/SodaLive/Sources/Live/Room/LiveRoomViewModel.swift index a2d88d2..59461d1 100644 --- a/SodaLive/Sources/Live/Room/LiveRoomViewModel.swift +++ b/SodaLive/Sources/Live/Room/LiveRoomViewModel.swift @@ -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 @Published var menu = "" @Published var menuList = [GetMenuPresetResponse]() @@ -1881,7 +1890,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject { completion: { [unowned self] errorCode in if errorCode == .errorOk { let (nickname, _) = self.getUserNicknameAndProfileUrl(accountId: UserDefaults.int(forKey: .userId)) - self.messages.append(LiveRoomHeartDonationChat(nickname: nickname)) + self.addHeartMessage(nickname: nickname) totalHeartCount += 1 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() { if heartTimer == nil { 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 { self.getRoomInfo() } else if decoded.type == .HEART_DONATION { - self.messages.append(LiveRoomHeartDonationChat(nickname: nickname)) + self.addHeartMessage(nickname: nickname) self.totalHeartCount += decoded.can self.addHeart() } diff --git a/SodaLive/Sources/Live/Room/V2/Component/View/LiveRoomChatView.swift b/SodaLive/Sources/Live/Room/V2/Component/View/LiveRoomChatView.swift index f70936f..9b614b6 100644 --- a/SodaLive/Sources/Live/Room/V2/Component/View/LiveRoomChatView.swift +++ b/SodaLive/Sources/Live/Room/V2/Component/View/LiveRoomChatView.swift @@ -28,10 +28,6 @@ struct LiveRoomChatView: View { let chatMessage = messages[index] as! LiveRoomJoinChat LiveRoomJoinChatItemView(chatMessage: chatMessage) - case LiveRoomChatType.HEART: - let chatMessage = messages[index] as! LiveRoomHeartDonationChat - LiveRoomHeartDonationChatItemView(chatMessage: chatMessage) - default: let chatMessage = messages[index] as! LiveRoomNormalChat LiveRoomChatItemView( diff --git a/SodaLive/Sources/Live/Room/V2/LiveRoomViewV2.swift b/SodaLive/Sources/Live/Room/V2/LiveRoomViewV2.swift index 2245a56..323f6f7 100644 --- a/SodaLive/Sources/Live/Room/V2/LiveRoomViewV2.swift +++ b/SodaLive/Sources/Live/Room/V2/LiveRoomViewV2.swift @@ -289,6 +289,11 @@ struct LiveRoomViewV2: View { } } + if let heartNickname = viewModel.heartNickname { + LiveRoomHeartDonationChatItemView(nickname: heartNickname) + .padding(.top, 16) + } + if viewModel.isShowNotice { VStack(alignment: .leading, spacing: 0) { Image("ic_notice_triangle")