fix(deeplink): 커뮤니티 댓글 딥링크를 보강한다
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user