From a41c4239917607eda0b6baba22e30ab9a7246ed2 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Fri, 1 Sep 2023 00:35:50 +0900 Subject: [PATCH] =?UTF-8?q?=ED=91=B8=EC=8B=9C,=20=EB=94=A5=EB=A7=81?= =?UTF-8?q?=ED=81=AC=20-=20=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=ED=83=AD?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=95=84=EB=8F=84=20=EC=8B=A4=ED=96=89=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SodaLive/Sources/App/AppDelegate.swift | 14 +++++- SodaLive/Sources/App/AppState.swift | 1 + SodaLive/Sources/App/SodaLiveApp.swift | 9 +++- SodaLive/Sources/Live/LiveView.swift | 38 ---------------- SodaLive/Sources/Main/Home/HomeView.swift | 54 +++++++++++++++++++++++ 5 files changed, 75 insertions(+), 41 deletions(-) diff --git a/SodaLive/Sources/App/AppDelegate.swift b/SodaLive/Sources/App/AppDelegate.swift index c2fac8f..ef267e2 100644 --- a/SodaLive/Sources/App/AppDelegate.swift +++ b/SodaLive/Sources/App/AppDelegate.swift @@ -95,16 +95,26 @@ extension AppDelegate : UNUserNotificationCenterDelegate { Messaging.messaging().appDidReceiveMessage(userInfo) let roomIdString = userInfo["room_id"] as? String - let audioContentIdString = userInfo["audio_content_id"] as? String + let contentIdString = userInfo["content_id"] as? String + let channelIdString = userInfo["channel_id"] as? String + let messageIdString = userInfo["message_id"] as? String if let roomIdString = roomIdString, let roomId = Int(roomIdString), roomId > 0 { AppState.shared.pushRoomId = roomId } - if let audioContentIdString = audioContentIdString, let audioContentId = Int(audioContentIdString), audioContentId > 0 { + if let contentIdString = contentIdString, let audioContentId = Int(contentIdString), audioContentId > 0 { AppState.shared.pushAudioContentId = audioContentId } + if let channelIdString = channelIdString, let channelId = Int(channelIdString), channelId > 0 { + AppState.shared.pushChannelId = channelId + } + + if let messageIdString = messageIdString, let messageId = Int(messageIdString), messageId > 0 { + AppState.shared.pushMessageId = messageId + } + completionHandler() } } diff --git a/SodaLive/Sources/App/AppState.swift b/SodaLive/Sources/App/AppState.swift index 89b7ee0..a865cc1 100644 --- a/SodaLive/Sources/App/AppState.swift +++ b/SodaLive/Sources/App/AppState.swift @@ -26,6 +26,7 @@ class AppState: ObservableObject { @Published var pushRoomId = 0 @Published var pushChannelId = 0 + @Published var pushMessageId = 0 @Published var pushAudioContentId = 0 @Published var roomId = 0 { didSet { diff --git a/SodaLive/Sources/App/SodaLiveApp.swift b/SodaLive/Sources/App/SodaLiveApp.swift index f278616..4fc9c53 100644 --- a/SodaLive/Sources/App/SodaLiveApp.swift +++ b/SodaLive/Sources/App/SodaLiveApp.swift @@ -26,7 +26,8 @@ struct SodaLiveApp: App { let queryItems = URLComponents(url: url, resolvingAgainstBaseURL: true)?.queryItems let roomId = queryItems?.filter({$0.name == "room_id"}).first?.value let channelId = queryItems?.filter({$0.name == "channel_id"}).first?.value - let audioContentId = queryItems?.filter({$0.name == "audio_content_id"}).first?.value + let messageId = queryItems?.filter({$0.name == "message_id"}).first?.value + let audioContentId = queryItems?.filter({$0.name == "content_id"}).first?.value if let roomId = roomId { DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { @@ -40,6 +41,12 @@ struct SodaLiveApp: App { } } + if let messageId = messageId { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + AppState.shared.pushMessageId = Int(messageId) ?? 0 + } + } + if let audioContentId = audioContentId { DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { AppState.shared.pushAudioContentId = Int(audioContentId) ?? 0 diff --git a/SodaLive/Sources/Live/LiveView.swift b/SodaLive/Sources/Live/LiveView.swift index ba0c662..d974380 100644 --- a/SodaLive/Sources/Live/LiveView.swift +++ b/SodaLive/Sources/Live/LiveView.swift @@ -141,44 +141,6 @@ struct LiveView: View { } } } - .valueChanged(value: appState.pushRoomId) { value in - DispatchQueue.main.async { - appState.setAppStep(step: .main) - - if value > 0 { - viewModel.enterRoom(roomId: value) - } - } - } - .valueChanged(value: appState.pushChannelId) { value in - DispatchQueue.main.async { - appState.setAppStep(step: .main) - - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - if value > 0 { - appState.setAppStep(step: .creatorDetail(userId: value)) - } - } - } - } - .valueChanged(value: appState.pushAudioContentId) { value in - appState.setAppStep(step: .main) - - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - if value > 0 { - appState.setAppStep(step: .contentDetail(contentId: value)) - } - } - } - .onAppear { - if appState.pushRoomId > 0 { - viewModel.enterRoom(roomId: appState.pushRoomId) - } else if appState.pushChannelId > 0 { - appState.setAppStep(step: .creatorDetail(userId: appState.pushChannelId)) - } else if appState.pushAudioContentId > 0 { - appState.setAppStep(step: .contentDetail(contentId: appState.pushAudioContentId)) - } - } } private func onCreateSuccess(response: CreateLiveRoomResponse) { diff --git a/SodaLive/Sources/Main/Home/HomeView.swift b/SodaLive/Sources/Main/Home/HomeView.swift index b7cbce1..b9cd1b0 100644 --- a/SodaLive/Sources/Main/Home/HomeView.swift +++ b/SodaLive/Sources/Main/Home/HomeView.swift @@ -13,6 +13,7 @@ import Kingfisher struct HomeView: View { @StateObject var viewModel = HomeViewModel() + @StateObject var liveViewModel = LiveViewModel() @StateObject var appState = AppState.shared @StateObject var contentPlayManager = ContentPlayManager.shared @@ -142,6 +143,59 @@ struct HomeView: View { } } .edgesIgnoringSafeArea(.bottom) + .valueChanged(value: appState.pushRoomId) { value in + DispatchQueue.main.async { + appState.setAppStep(step: .main) + + if value > 0 { + liveViewModel.enterRoom(roomId: value) + } + } + } + .valueChanged(value: appState.pushChannelId) { value in + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + if value > 0 { + appState.setAppStep(step: .main) + appState.setAppStep(step: .creatorDetail(userId: value)) + } + } + } + .valueChanged(value: appState.pushMessageId) { value in + DispatchQueue.main.async { + appState.setAppStep(step: .main) + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + if value > 0 { + viewModel.currentTab = .message + } + } + } + } + .valueChanged(value: appState.pushAudioContentId) { value in + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + if value > 0 { + appState.setAppStep(step: .main) + appState.setAppStep(step: .contentDetail(contentId: value)) + } + } + } + .onAppear { + if appState.pushRoomId > 0 { + DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { + liveViewModel.enterRoom(roomId: appState.pushRoomId) + } + } else if appState.pushChannelId > 0 { + DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { + appState.setAppStep(step: .creatorDetail(userId: appState.pushChannelId)) + } + } else if appState.pushAudioContentId > 0 { + DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { + appState.setAppStep(step: .contentDetail(contentId: appState.pushAudioContentId)) + } + } else if appState.pushMessageId > 0 { + viewModel.currentTab = .message + } + } } }