Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f9863b7
Add getPluginDetails action to ZendeskManager
iamgabrielma Nov 2, 2022
a38b305
Add plugin list and completion handler callback
iamgabrielma Nov 2, 2022
f44fca0
Try to get plugins by observing changes in Storage
iamgabrielma Nov 2, 2022
783e34a
Append ipp tags if needed to decorated tags
iamgabrielma Nov 2, 2022
914d74b
Add logic for plugin status
iamgabrielma Nov 2, 2022
1c97557
Experiment with async call for tag retrieval
iamgabrielma Nov 3, 2022
7a3b9ce
Return all tags on creating ZD request
iamgabrielma Nov 3, 2022
6f9a3fd
Remove unused vars
iamgabrielma Nov 4, 2022
4b39882
Move plugin slugs to Constants enum
iamgabrielma Nov 4, 2022
75cb967
Access control changes. Make func private.
iamgabrielma Nov 4, 2022
e243aaa
Extract logic to SettingsViewModel
iamgabrielma Nov 7, 2022
b59a59d
Rename variables for clarity. Add comments.
iamgabrielma Nov 7, 2022
96b123d
Move logic to ZendeskManager
iamgabrielma Nov 9, 2022
9a1ae44
Remove unnecessary variable
iamgabrielma Nov 9, 2022
849862e
Remove unused extension from SettingsViewModel
iamgabrielma Nov 9, 2022
10fcac6
Make enum cases snakecase and split them
iamgabrielma Nov 9, 2022
c364689
Make ippPluginstatuses non-optional
iamgabrielma Nov 9, 2022
16affe8
Fix opening brace violation
iamgabrielma Nov 9, 2022
37b95b5
Move ResultsController outside of ZendeskManager init
iamgabrielma Nov 9, 2022
f82b2c9
Access ZD shared from SwitchStore
iamgabrielma Nov 9, 2022
e88a7a3
Make pluginResultsController lazy
iamgabrielma Nov 9, 2022
dca42e5
Add missing method to MockZendeskManager
iamgabrielma Nov 9, 2022
9984996
Rename method for clarity. Typo.
iamgabrielma Nov 10, 2022
d341fc5
Remove trailing whitespace
iamgabrielma Nov 10, 2022
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
69 changes: 66 additions & 3 deletions WooCommerce/Classes/Tools/Zendesk/ZendeskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import CoreTelephony
import SafariServices
import Yosemite


extension NSNotification.Name {
static let ZDPNReceived = NSNotification.Name(rawValue: "ZDPNReceived")
static let ZDPNCleared = NSNotification.Name(rawValue: "ZDPNCleared")
Expand Down Expand Up @@ -138,6 +137,40 @@ struct ZendeskProvider {
///
#if !targetEnvironment(macCatalyst)
final class ZendeskManager: NSObject, ZendeskManagerProtocol {
/// Loads Plugins from the Storage Layer.
///
private let pluginResultsController: ResultsController<StorageSitePlugin>

private let stores = ServiceLocator.stores

private let storageManager = ServiceLocator.storageManager

/// IPP plugin statuses
///
private var ippPluginstatuses: [String]? {
var ippTags = [String]()
if let stripe = pluginResultsController.fetchedObjects.first(where: { $0.plugin == IPPPluginStatus.stripe_plugin_slug }) {
if stripe.status == .active {
ippTags.append(IPPPluginStatus.woo_mobile_stripe_installed_and_activated)
} else if stripe.status == .inactive {
ippTags.append(IPPPluginStatus.woo_mobile_stripe_installed_and_not_activated)
}
} else {
ippTags.append(IPPPluginStatus.woo_mobile_stripe_not_installed)
}
if let wcpay = pluginResultsController.fetchedObjects.first(where: { $0.plugin == IPPPluginStatus.wcpay_plugin_slug }) {
if wcpay.status == .active {
ippTags.append(IPPPluginStatus.woo_mobile_wcpay_installed_and_activated)
} else if wcpay.status == .inactive {
ippTags.append(IPPPluginStatus.woo_mobile_wcpay_installed_and_not_activated)
}
}
else {
ippTags.append(IPPPluginStatus.woo_mobile_wcpay_not_installed)
}
return ippTags
}

func showNewRequestIfPossible(from controller: UIViewController) {
showNewRequestIfPossible(from: controller, with: nil)
}
Expand Down Expand Up @@ -185,10 +218,24 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
return ZDKPushProvider(zendesk: zendesk)
}


/// Designated Initialier
///
fileprivate override init() {
/// Initialize Plugins Results Controller
let sitePredicate: NSPredicate?
let pluginStatusDescriptor = [NSSortDescriptor(keyPath: \StorageSitePlugin.status, ascending: true)]

if let siteID = stores.sessionManager.defaultSite?.siteID {
sitePredicate = NSPredicate(format: "siteID == %lld", siteID)
} else {
sitePredicate = nil
DDLogError("ZendeskManager: No siteID found when attempting to initialize Plugins Results predicate.")
}
pluginResultsController = ResultsController(storageManager: storageManager,
matching: sitePredicate,
sortedBy: pluginStatusDescriptor)


super.init()
observeZendeskNotifications()
}
Expand Down Expand Up @@ -324,7 +371,10 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
/// The SDK tag is used in a trigger and displays tickets in Woo > Mobile Apps New.
///
func getTags(supportSourceTag: String?) -> [String] {
let tags = [Constants.platformTag, Constants.sdkTag, Constants.jetpackTag]
var tags = [Constants.platformTag, Constants.sdkTag, Constants.jetpackTag]

// Get IPP plugin statuses
tags.append(contentsOf: ippPluginstatuses ?? [])

return decorateTags(tags: tags, supportSourceTag: supportSourceTag)
}
Expand Down Expand Up @@ -1066,6 +1116,19 @@ private extension ZendeskManager {
}
}

private extension ZendeskManager {
enum IPPPluginStatus {
static let stripe_plugin_slug = "woocommerce-gateway-stripe/woocommerce-gateway-stripe"
static let wcpay_plugin_slug = "woocommerce-payments/woocommerce-payments"
static let woo_mobile_stripe_not_installed = "woo_mobile_stripe_not_installed"
static let woo_mobile_stripe_installed_and_not_activated = "woo_mobile_stripe_installed_and_not_activated"
static let woo_mobile_stripe_installed_and_activated = "woo_mobile_stripe_installed_and_activated"
static let woo_mobile_wcpay_not_installed = "woo_mobile_wcpay_not_installed"
static let woo_mobile_wcpay_installed_and_not_activated = "woo_mobile_wcpay_installed_and_not_activated"
static let woo_mobile_wcpay_installed_and_activated = "woo_mobile_wcpay_installed_and_activated"
static let woo_mobile_site_plugins_fetching_error = "woo_mobile_site_plugins_fetching_error"
}
}

// MARK: - UITextFieldDelegate
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ private extension SettingsViewModel {
// MARK: - Localizations
//
private extension SettingsViewModel {
enum IPPPluginStatus {
static let stripe_plugin_slug = "woocommerce-gateway-stripe/woocommerce-gateway-stripe"
static let wcpay_plugin_slug = "woocommerce-payments/woocommerce-payments"
static let woo_mobile_stripe_not_installed = "woo_mobile_stripe_not_installed"
static let woo_mobile_stripe_installed_and_not_activated = "woo_mobile_stripe_installed_and_not_activated"
static let woo_mobile_stripe_installed_and_activated = "woo_mobile_stripe_installed_and_activated"
static let woo_mobile_wcpay_not_installed = "woo_mobile_wcpay_not_installed"
static let woo_mobile_wcpay_installed_and_not_activated = "woo_mobile_wcpay_installed_and_not_activated"
static let woo_mobile_wcpay_installed_and_activated = "woo_mobile_wcpay_installed_and_activated"
static let woo_mobile_site_plugins_fetching_error = "woo_mobile_site_plugins_fetching_error"
}
enum Localization {
static let pluginsTitle = NSLocalizedString(
"Plugins",
Expand Down