From bf5f5e46a1c0dc659c42d43a2cf081b56796deda Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 6 May 2026 11:05:37 +1200 Subject: [PATCH] Format files in preparation for JetpackSocial migration --- WordPress/Classes/Utility/AccountHelper.swift | 34 ++++++++----- .../BuildInformation/FeatureFlag.swift | 10 ++-- .../BlogDetailsViewController+Swift.swift | 51 ++++++++++++------- ...haringAuthorizationWebViewController.swift | 40 ++++++++++----- .../CustomPostSettingsViewModel.swift | 16 +++--- .../Post/PostSettings/PostSettingsView.swift | 17 +++++-- 6 files changed, 107 insertions(+), 61 deletions(-) diff --git a/WordPress/Classes/Utility/AccountHelper.swift b/WordPress/Classes/Utility/AccountHelper.swift index 4edbadaa4410..db490fb4c4e7 100644 --- a/WordPress/Classes/Utility/AccountHelper.swift +++ b/WordPress/Classes/Utility/AccountHelper.swift @@ -20,13 +20,14 @@ import WordPressData @objc static var isLoggedIn: Bool { get { - return !(noSelfHostedBlogs && noWordPressDotComAccount) + !(noSelfHostedBlogs && noWordPressDotComAccount) } } @objc static var noSelfHostedBlogs: Bool { let context = ContextManager.shared.mainContext - return BlogQuery().hostedByWPCom(false).count(in: context) == 0 && (try? Blog.hasAnyJetpackBlogs(in: context)) == false + return BlogQuery().hostedByWPCom(false).count(in: context) == 0 + && (try? Blog.hasAnyJetpackBlogs(in: context)) == false } static var hasBlogs: Bool { @@ -35,7 +36,7 @@ import WordPressData } @objc static var noWordPressDotComAccount: Bool { - return !AccountHelper.isDotcomAvailable() + !AccountHelper.isDotcomAvailable() } static var defaultSiteId: NSNumber? { @@ -60,15 +61,19 @@ import WordPressData let otherAccounts = accountCount > 1 ? " + \(accountCount - 1) others" : "" let accountsDescription = "wp.com account: " + (defaultAccount?.logDescription ?? "") + otherAccounts - let blogTree = blogsByAccount.map({ (account, blogs) -> String in - let accountDescription = account?.logDescription ?? "" - let isDefault = (account != nil && account == defaultAccount) ? " (default)" : "" - let blogsDescription = blogs.map({ (blog) -> String in - return "└─ " + blog.logDescription - }).joined(separator: "\n") - - return accountDescription + isDefault + "\n" + blogsDescription - }).joined(separator: "\n") + let blogTree = + blogsByAccount.map({ (account, blogs) -> String in + let accountDescription = account?.logDescription ?? "" + let isDefault = (account != nil && account == defaultAccount) ? " (default)" : "" + let blogsDescription = + blogs.map({ (blog) -> String in + "└─ " + blog.logDescription + }) + .joined(separator: "\n") + + return accountDescription + isDefault + "\n" + blogsDescription + }) + .joined(separator: "\n") let blogTreeDescription = !blogsByAccount.isEmpty ? blogTree : "No account/blogs configured on device" DDLogInfo("\(accountsDescription)\nAll accounts and blogs:\n\(blogTreeDescription)") @@ -82,8 +87,9 @@ import WordPressData // We don't just clear all reminders, in case the user has self-hosted // sites added to the app. if let account = try? WPAccount.lookupDefaultWordPressComAccount(in: ContextManager.shared.mainContext), - let blogs = account.blogs, - let scheduler = try? ReminderScheduleCoordinator() { + let blogs = account.blogs, + let scheduler = try? ReminderScheduleCoordinator() + { blogs.forEach { scheduler.unschedule(for: $0) } } diff --git a/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift b/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift index 800d1dfaaf22..a9d2e9ef6c96 100644 --- a/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift +++ b/WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift @@ -96,7 +96,7 @@ public enum FeatureFlag: Int, CaseIterable { } var disabled: Bool { - return enabled == false + enabled == false } } @@ -106,14 +106,14 @@ public enum FeatureFlag: Int, CaseIterable { public class Feature: NSObject { /// Returns a boolean indicating if the feature is enabled @objc public static func enabled(_ feature: FeatureFlag) -> Bool { - return feature.enabled + feature.enabled } } extension FeatureFlag { /// Descriptions used to display the feature flag override menu in debug builds public var description: String { - return switch self { + switch self { case .signUp: "Sign Up" case .domainRegistration: "Domain Registration" case .selfHostedSites: "Self-Hosted Sites" @@ -144,7 +144,7 @@ extension FeatureFlag { extension FeatureFlag: OverridableFlag { var originalValue: Bool { - return enabled + enabled } var key: String { @@ -160,6 +160,6 @@ extension FeatureFlag: RolloutConfigurableFlag { /// If a percentage rollout isn't applicable for the flag, return nil. /// var rolloutPercentage: Double? { - return nil + nil } } diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+Swift.swift b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+Swift.swift index 9d742cbe45c9..9f32efa4d2a3 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+Swift.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+Swift.swift @@ -108,13 +108,14 @@ extension BlogDetailsViewController { blog: blog, localizedFeatureName: feature, source: "custom_post_types", - presentingViewController: self) { [blog, weak self] client in - CustomPostTypesView( - blog: blog, - service: CustomPostTypeService(client: client, blog: blog), - presentingViewController: self - ) - } + presentingViewController: self + ) { [blog, weak self] client in + CustomPostTypesView( + blog: blog, + service: CustomPostTypeService(client: client, blog: blog), + presentingViewController: self + ) + } let controller = UIHostingController(rootView: rootView) controller.navigationItem.largeTitleDisplayMode = .never presentationDelegate?.presentBlogDetailsViewController(controller) @@ -130,14 +131,15 @@ extension BlogDetailsViewController { blog: blog, localizedFeatureName: feature, source: "custom_post_types", - presentingViewController: self) { [blog, weak self] client in - PinnedPostTypeView( - blog: blog, - service: CustomPostTypeService(client: client, blog: blog), - postType: postType, - presentingViewController: self - ) - } + presentingViewController: self + ) { [blog, weak self] client in + PinnedPostTypeView( + blog: blog, + service: CustomPostTypeService(client: client, blog: blog), + postType: postType, + presentingViewController: self + ) + } let controller = UIHostingController(rootView: rootView) controller.navigationItem.largeTitleDisplayMode = .never presentationDelegate?.presentBlogDetailsViewController(controller) @@ -317,7 +319,11 @@ extension BlogDetailsViewController { guard let presentationDelegate else { return wpAssertionFailure("presentationDelegate mising") } - DomainsDashboardCoordinator.presentDomainsDashboard(with: presentationDelegate, source: source.string, blog: blog) + DomainsDashboardCoordinator.presentDomainsDashboard( + with: presentationDelegate, + source: source.string, + blog: blog + ) } public func showJetpackSettings() { @@ -388,8 +394,17 @@ extension BlogDetailsViewController { } public func showApplicationPasswords() { - let feature = NSLocalizedString("applicationPasswordRequired.feature.applicationPasswords", value: "Application Passwords Management", comment: "Feature name for managing application passwords in the app") - let view = ApplicationPasswordRequiredView(blog: blog, localizedFeatureName: feature, source: "application_passwords", presentingViewController: self) { + let feature = NSLocalizedString( + "applicationPasswordRequired.feature.applicationPasswords", + value: "Application Passwords Management", + comment: "Feature name for managing application passwords in the app" + ) + let view = ApplicationPasswordRequiredView( + blog: blog, + localizedFeatureName: feature, + source: "application_passwords", + presentingViewController: self + ) { ApplicationTokenListView(dataProvider: ApplicationPasswordService(api: $0)) } presentationDelegate?.presentBlogDetailsViewController(UIHostingController(rootView: view)) diff --git a/WordPress/Classes/ViewRelated/Blog/Sharing/SharingAuthorizationWebViewController.swift b/WordPress/Classes/ViewRelated/Blog/Sharing/SharingAuthorizationWebViewController.swift index 6f9beb4101d1..902b398c1512 100644 --- a/WordPress/Classes/ViewRelated/Blog/Sharing/SharingAuthorizationWebViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Sharing/SharingAuthorizationWebViewController.swift @@ -44,13 +44,13 @@ class SharingAuthorizationWebViewController: WebKitViewController { fatalError("init(coder:) has not been implemented") } - // MARK: - View Lifecycle + // MARK: - View Lifecycle - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) - cleanupCookies() - } + cleanupCookies() + } // MARK: - Cookies Management @@ -62,8 +62,9 @@ class SharingAuthorizationWebViewController: WebKitViewController { func saveHostForCookiesCleanup(from url: URL) { guard let host = url.host, !host.contains("wordpress"), - !hosts.contains(host) else { - return + !hosts.contains(host) + else { + return } let components = host.components(separatedBy: ".") @@ -117,16 +118,25 @@ class SharingAuthorizationWebViewController: WebKitViewController { // MARK: - WKNavigationDelegate extension SharingAuthorizationWebViewController { - override func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { + override func webView( + _ webView: WKWebView, + decidePolicyFor navigationAction: WKNavigationAction, + decisionHandler: @escaping (WKNavigationActionPolicy) -> Void + ) { decidePolicy(webView: webView, navigationAction: navigationAction, decisionHandler: decisionHandler) } - private func decidePolicy(webView: WKWebView, navigationAction: WKNavigationAction, decisionHandler: @escaping @MainActor @Sendable (WKNavigationActionPolicy) -> Void) { + private func decidePolicy( + webView: WKWebView, + navigationAction: WKNavigationAction, + decisionHandler: @escaping @MainActor @Sendable (WKNavigationActionPolicy) -> Void + ) { // Prevent a second verify load by someone happy clicking. guard !loadingVerify, - let url = navigationAction.request.url else { - decisionHandler(.cancel) - return + let url = navigationAction.request.url + else { + decisionHandler(.cancel) + return } let action = PublicizeConnectionURLMatcher.authorizeAction(for: url) @@ -150,7 +160,11 @@ extension SharingAuthorizationWebViewController { } } - override func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { + override func webView( + _ webView: WKWebView, + didFailProvisionalNavigation navigation: WKNavigation!, + withError error: Error + ) { if loadingVerify && (error as NSError).code == NSURLErrorCancelled { // Authenticating to Facebook and Twitter can return an false // NSURLErrorCancelled (-999) error. However the connection still succeeds. diff --git a/WordPress/Classes/ViewRelated/Post/PostSettings/CustomPostSettingsViewModel.swift b/WordPress/Classes/ViewRelated/Post/PostSettings/CustomPostSettingsViewModel.swift index 6570975c504f..73cdfb01e1a4 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettings/CustomPostSettingsViewModel.swift +++ b/WordPress/Classes/ViewRelated/Post/PostSettings/CustomPostSettingsViewModel.swift @@ -120,7 +120,8 @@ final class CustomPostSettingsViewModel: NSObject, ObservableObject, PostSetting var postFormatText: String { guard capabilities.supportsPostFormats else { return "" } - return blog.postFormatText(fromSlug: settings.postFormat) ?? NSLocalizedString("Standard", comment: "Default post format") + return blog.postFormatText(fromSlug: settings.postFormat) + ?? NSLocalizedString("Standard", comment: "Default post format") } var timeZone: TimeZone { @@ -201,8 +202,9 @@ final class CustomPostSettingsViewModel: NSObject, ObservableObject, PostSetting var initialSettings = editorService.settings // Resolve author display name from Blog's cached authors if let authorId = initialSettings.author?.id, - let authors = blog.authors, - let author = authors.first(where: { $0.userID.intValue == authorId }) { + let authors = blog.authors, + let author = authors.first(where: { $0.userID.intValue == authorId }) + { initialSettings.author = PostSettings.Author( id: authorId, displayName: author.displayName ?? "–", @@ -232,9 +234,11 @@ final class CustomPostSettingsViewModel: NSObject, ObservableObject, PostSetting super.init() - featuredImageViewModel?.$selection.dropFirst().sink { [weak self] media in - self?.settings.featuredImageID = media?.mediaID?.intValue - }.store(in: &cancellables) + featuredImageViewModel?.$selection.dropFirst() + .sink { [weak self] media in + self?.settings.featuredImageID = media?.mediaID?.intValue + } + .store(in: &cancellables) WPAnalytics.track(.postSettingsShown) diff --git a/WordPress/Classes/ViewRelated/Post/PostSettings/PostSettingsView.swift b/WordPress/Classes/ViewRelated/Post/PostSettings/PostSettingsView.swift index 2d2c22a4c1a2..15490080a521 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettings/PostSettingsView.swift +++ b/WordPress/Classes/ViewRelated/Post/PostSettings/PostSettingsView.swift @@ -145,7 +145,8 @@ struct PostSettingsFormContentView: Vi } if viewModel.capabilities.supportsCategories || viewModel.capabilities.supportsTags - || !viewModel.capabilities.customTaxonomySlugs.isEmpty { + || !viewModel.capabilities.customTaxonomySlugs.isEmpty + { organizationSection } if viewModel.capabilities.supportsExcerpt { @@ -453,14 +454,18 @@ struct PostSettingsFormContentView: Vi NavigationLink { PostDiscussionSettingsView(postSettings: $viewModel.settings) } label: { - SettingsRow(Strings.discussionLabel, value: viewModel.settings.allowComments ? Strings.discussionOpen : Strings.discussionClosed) + SettingsRow( + Strings.discussionLabel, + value: viewModel.settings.allowComments ? Strings.discussionOpen : Strings.discussionClosed + ) } } @ViewBuilder private var parentPageRow: some View { if viewModel.capabilities.supportsPageAttributes, - let destination = viewModel.parentPagePickerDestination() { + let destination = viewModel.parentPagePickerDestination() + { NavigationLink { destination } label: { @@ -691,7 +696,8 @@ private enum Strings { static let slugHint = NSLocalizedString( "postSettings.slug.hint", value: "The slug is the URL-friendly version of the post title.", - comment: "Hint text for the slug field. Should be the same as the text displayed if the user clicks the (i) in Slug in Calypso." + comment: + "Hint text for the slug field. Should be the same as the text displayed if the user clicks the (i) in Slug in Calypso." ) static let stickyPostLabel = NSLocalizedString( @@ -745,7 +751,8 @@ private enum Strings { static let readyToPublish = NSLocalizedString( "prepublishing.publishingSectionTitle", value: "Ready to Publish?", - comment: "The title of the top section that shows the site your are publishing to. Default is 'Ready to Publish?'" + comment: + "The title of the top section that shows the site your are publishing to. Default is 'Ready to Publish?'" ) static let statusAndVisibility = NSLocalizedString(