From 55d26594489c273bca05415148c56bfb2378b2e9 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Thu, 18 Mar 2021 15:43:12 -0400 Subject: [PATCH] Use collection.url rather than server + collection alias in share sheets --- iOS/PostEditor/PostEditorView.swift | 8 +++++--- macOS/Navigation/ActivePostToolbarView.swift | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/iOS/PostEditor/PostEditorView.swift b/iOS/PostEditor/PostEditorView.swift index d866cc7..92c4e06 100644 --- a/iOS/PostEditor/PostEditorView.swift +++ b/iOS/PostEditor/PostEditorView.swift @@ -207,11 +207,13 @@ struct PostEditorView: View { if let postSlug = post.slug, let postCollectionAlias = post.collectionAlias { - // This post is in a collection, so share the URL as server/collectionAlias/postSlug. - urlString = "\(model.account.server)/\((postCollectionAlias))/\((postSlug))" + // This post is in a collection, so share the URL as baseURL/postSlug. + let urls = collections.filter { $0.alias == postCollectionAlias } + let baseURL = urls.first?.url ?? "\(model.account.server)/\(postCollectionAlias)/" + urlString = "\(baseURL)\(postSlug)" } else { // This is a draft post, so share the URL as server/postID - urlString = "\(model.account.server)/\((postId))" + urlString = "\(model.account.server)/\(postId)" } guard let data = URL(string: urlString) else { return } diff --git a/macOS/Navigation/ActivePostToolbarView.swift b/macOS/Navigation/ActivePostToolbarView.swift index f95d123..1319400 100644 --- a/macOS/Navigation/ActivePostToolbarView.swift +++ b/macOS/Navigation/ActivePostToolbarView.swift @@ -106,9 +106,20 @@ struct ActivePostToolbarView: View { private func createPostUrl() -> [Any] { guard let postId = model.selectedPost?.postId else { return [] } - guard let urlString = model.selectedPost?.slug != nil ? - "\(model.account.server)/\((model.selectedPost?.collectionAlias)!)/\((model.selectedPost?.slug)!)" : - "\(model.account.server)/\((postId))" else { return [] } + + var urlString: String + + if let postSlug = model.selectedPost?.slug, + let postCollectionAlias = model.selectedPost?.collectionAlias { + // This post is in a collection, so share the URL as baseURL/postSlug + let urls = collections.filter { $0.alias == postCollectionAlias } + let baseURL = urls.first?.url ?? "\(model.account.server)/\(postCollectionAlias)/" + urlString = "\(baseURL)\(postSlug)" + } else { + // This is a draft post, sho share the URL as server/postID + urlString = "\(model.account.server)/\(postId)" + } + guard let data = URL(string: urlString) else { return [] } return [data as NSURL] }