fix(deeplink): 커뮤니티 댓글 딥링크를 보강한다

This commit is contained in:
Yu Sung
2026-03-13 21:39:45 +09:00
parent 3d4f67dbd5
commit de627e1700
5 changed files with 192 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ enum AppDeepLinkAction {
case live(roomId: Int)
case content(contentId: Int)
case series(seriesId: Int)
case community(creatorId: Int)
case community(creatorId: Int, postId: Int?)
case message
case audition
}
@@ -65,8 +65,15 @@ enum AppDeepLinkHandler {
guard seriesId > 0 else { return }
AppState.shared.setAppStep(step: .seriesDetail(seriesId: seriesId))
case .community(let creatorId):
case .community(let creatorId, let postId):
guard creatorId > 0 else { return }
if let postId = postId, postId > 0 {
AppState.shared.setPendingCommunityCommentDeepLink(creatorId: creatorId, postId: postId)
} else {
AppState.shared.clearPendingCommunityCommentDeepLink()
}
AppState.shared.setAppStep(step: .creatorCommunityAll(creatorId: creatorId))
case .message:
@@ -102,7 +109,7 @@ enum AppDeepLinkHandler {
if !host.isEmpty {
let identifier = pathComponents.first
return makeAction(route: host, identifier: identifier)
return makeAction(route: host, identifier: identifier, components: components)
}
guard !pathComponents.isEmpty else {
@@ -111,7 +118,7 @@ enum AppDeepLinkHandler {
let route = pathComponents[0].lowercased()
let identifier = pathComponents.count > 1 ? pathComponents[1] : nil
return makeAction(route: route, identifier: identifier)
return makeAction(route: route, identifier: identifier, components: components)
}
private static func parseQueryStyle(components: URLComponents?) -> AppDeepLinkAction? {
@@ -137,7 +144,7 @@ enum AppDeepLinkHandler {
}
if let communityId = queryMap["community_id"], let value = Int(communityId), value > 0 {
return .community(creatorId: value)
return .community(creatorId: value, postId: communityPostId(queryMap: queryMap))
}
if queryMap["message_id"] != nil {
@@ -151,7 +158,7 @@ enum AppDeepLinkHandler {
return nil
}
private static func makeAction(route: String, identifier: String?) -> AppDeepLinkAction? {
private static func makeAction(route: String, identifier: String?, components: URLComponents?) -> AppDeepLinkAction? {
switch route {
case "live":
guard let identifier = identifier, let roomId = Int(identifier), roomId > 0 else {
@@ -172,15 +179,17 @@ enum AppDeepLinkHandler {
return .series(seriesId: seriesId)
case "community":
let postId = communityPostId(queryItems: components?.queryItems)
if let identifier = identifier, let creatorId = Int(identifier), creatorId > 0 {
return .community(creatorId: creatorId)
return .community(creatorId: creatorId, postId: postId)
}
guard let creatorId = fallbackCommunityCreatorId() else {
return nil
}
return .community(creatorId: creatorId)
return .community(creatorId: creatorId, postId: postId)
case "message":
return .message
@@ -193,6 +202,31 @@ enum AppDeepLinkHandler {
}
}
private static func communityPostId(queryItems: [URLQueryItem]?) -> Int? {
guard let queryItems = queryItems else {
return nil
}
var queryMap: [String: String] = [:]
for item in queryItems {
queryMap[item.name.lowercased()] = item.value
}
return communityPostId(queryMap: queryMap)
}
private static func communityPostId(queryMap: [String: String]) -> Int? {
if let postId = queryMap["postid"], let value = Int(postId), value > 0 {
return value
}
if let postId = queryMap["post_id"], let value = Int(postId), value > 0 {
return value
}
return nil
}
private static func fallbackCommunityCreatorId() -> Int? {
let userId = UserDefaults.int(forKey: .userId)
return userId > 0 ? userId : nil

View File

@@ -50,6 +50,8 @@ class AppState: ObservableObject {
@Published var pushAudioContentId = 0
@Published var pushSeriesId = 0
@Published var pendingDeepLinkAction: AppDeepLinkAction? = nil
@Published var pendingCommunityCommentCreatorId = 0
@Published var pendingCommunityCommentPostId = 0
@Published var isPushRoomFromDeepLink = false
@Published var roomId = 0 {
didSet {
@@ -149,6 +151,35 @@ class AppState: ObservableObject {
pendingDeepLinkAction = nil
return action
}
func setPendingCommunityCommentDeepLink(creatorId: Int, postId: Int) {
guard creatorId > 0, postId > 0 else {
return
}
pendingCommunityCommentCreatorId = creatorId
pendingCommunityCommentPostId = postId
}
func consumePendingCommunityCommentPostId(creatorId: Int) -> Int? {
guard creatorId > 0 else {
return nil
}
guard pendingCommunityCommentCreatorId == creatorId,
pendingCommunityCommentPostId > 0 else {
return nil
}
let postId = pendingCommunityCommentPostId
clearPendingCommunityCommentDeepLink()
return postId
}
func clearPendingCommunityCommentDeepLink() {
pendingCommunityCommentCreatorId = 0
pendingCommunityCommentPostId = 0
}
// ( -> ) UI
func softRestart() {

View File

@@ -144,6 +144,11 @@ struct CreatorCommunityAllView: View {
.sodaToast(isPresented: $playerManager.isShowPopup, message: playerManager.errorMessage, autohideIn: 2)
.onAppear {
viewModel.creatorId = creatorId
if let pendingPostId = AppState.shared.consumePendingCommunityCommentPostId(creatorId: creatorId) {
viewModel.openCommentListForDeepLink(postId: pendingPostId)
}
viewModel.getCommunityPostList()
}
.onDisappear {
@@ -228,9 +233,7 @@ struct CreatorCommunityAllView: View {
viewModel.communityPostLike(postId: item.postId)
},
onClickComment: {
viewModel.postId = item.postId
viewModel.isShowSecret = item.price > 0 && item.existOrdered && item.creatorId != UserDefaults.int(forKey: .userId)
viewModel.isShowCommentListView = true
viewModel.openCommentList(item: item)
},
onClickWriteComment: { comment, isSecret in
viewModel.createCommunityPostComment(

View File

@@ -117,6 +117,27 @@ class CreatorCommunityAllViewModel: ObservableObject {
.store(in: &subscription)
}
}
func openCommentList(item: GetCommunityPostListResponse) {
postId = item.postId
isShowSecret = shouldShowSecretCommentOption(item: item)
isShowCommentListView = true
}
func openCommentListForDeepLink(postId: Int) {
guard postId > 0 else {
return
}
if let targetPost = communityPostList.first(where: { $0.postId == postId }) {
openCommentList(item: targetPost)
return
}
self.postId = postId
self.isShowSecret = false
self.isShowCommentListView = true
}
func communityPostLike(postId: Int) {
repository.communityPostLike(postId: postId)
@@ -315,4 +336,8 @@ class CreatorCommunityAllViewModel: ObservableObject {
.store(in: &subscription)
}
}
private func shouldShowSecretCommentOption(item: GetCommunityPostListResponse) -> Bool {
item.price > 0 && item.existOrdered && item.creatorId != UserDefaults.int(forKey: .userId)
}
}