Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions WordPress/Classes/Utility/AccountHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,7 +36,7 @@ import WordPressData
}

@objc static var noWordPressDotComAccount: Bool {
return !AccountHelper.isDotcomAvailable()
!AccountHelper.isDotcomAvailable()
}

static var defaultSiteId: NSNumber? {
Expand All @@ -60,15 +61,19 @@ import WordPressData
let otherAccounts = accountCount > 1 ? " + \(accountCount - 1) others" : ""
let accountsDescription = "wp.com account: " + (defaultAccount?.logDescription ?? "<none>") + otherAccounts

let blogTree = blogsByAccount.map({ (account, blogs) -> String in
let accountDescription = account?.logDescription ?? "<Self-Hosted>"
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 ?? "<Self-Hosted>"
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)")
Expand All @@ -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) }
}

Expand Down
10 changes: 5 additions & 5 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public enum FeatureFlag: Int, CaseIterable {
}

var disabled: Bool {
return enabled == false
enabled == false
}
}

Expand All @@ -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"
Expand Down Expand Up @@ -144,7 +144,7 @@ extension FeatureFlag {
extension FeatureFlag: OverridableFlag {

var originalValue: Bool {
return enabled
enabled
}

var key: String {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: ".")
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ?? "–",
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ struct PostSettingsFormContentView<ViewModel: PostSettingsViewModelProtocol>: Vi
}
if viewModel.capabilities.supportsCategories
|| viewModel.capabilities.supportsTags
|| !viewModel.capabilities.customTaxonomySlugs.isEmpty {
|| !viewModel.capabilities.customTaxonomySlugs.isEmpty
{
organizationSection
}
if viewModel.capabilities.supportsExcerpt {
Expand Down Expand Up @@ -453,14 +454,18 @@ struct PostSettingsFormContentView<ViewModel: PostSettingsViewModelProtocol>: 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: {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down