Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class SwitchStoreUseCase: SwitchStoreUseCaseProtocol {

private let stores: StoresManager
private let storageManager: StorageManagerType
private let zendeskShared: ZendeskManagerProtocol = ZendeskProvider.shared

private lazy var resultsController: ResultsController<StorageSite> = {
return ResultsController(storageManager: storageManager, sortedBy: [])
Expand Down Expand Up @@ -72,7 +73,9 @@ final class SwitchStoreUseCase: SwitchStoreUseCaseProtocol {
// https://github.com/woocommerce/woocommerce-ios/pull/2013#discussion_r454620804
logOutOfCurrentStore {
self.finalizeStoreSelection(storeID)

// Inform the Zendesk shared instance that the Store has been switched
// https://github.com/woocommerce/woocommerce-ios/pull/8008/
self.zendeskShared.observeStoreSwitch()
onCompletion(true)
}
}
Expand Down
83 changes: 79 additions & 4 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 All @@ -23,6 +22,8 @@ extension NSNotification.Name {
protocol ZendeskManagerProtocol: SupportManagerAdapter {
typealias onUserInformationCompletion = (_ success: Bool, _ email: String?) -> Void

func observeStoreSwitch()

/// Displays the Zendesk New Request view from the given controller, for users to submit new tickets.
///
func showNewRequestIfPossible(from controller: UIViewController, with sourceTag: String?)
Expand All @@ -45,6 +46,10 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
}

struct NoZendeskManager: ZendeskManagerProtocol {
func observeStoreSwitch() {
// no-op
}

func showNewRequestIfPossible(from controller: UIViewController) {
// no-op
}
Expand Down Expand Up @@ -138,6 +143,63 @@ struct ZendeskProvider {
///
#if !targetEnvironment(macCatalyst)
final class ZendeskManager: NSObject, ZendeskManagerProtocol {
private let stores = ServiceLocator.stores
private let storageManager = ServiceLocator.storageManager

/// Loads Plugins from the Storage Layer.
///
private lazy var pluginResultsController: ResultsController<StorageSitePlugin> = updatePluginResultsController()

private func updatePluginResultsController() -> ResultsController<StorageSitePlugin> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit:

Suggested change
private func updatePluginResultsController() -> ResultsController<StorageSitePlugin> {
/// Returns a `pluginResultsController` using the latest selected site ID for predicate.
private func createPluginResultsController() -> ResultsController<StorageSitePlugin> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! create makes more sense than update as we're not really updating it but creating a new one on each call. Changed on 9984996

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

let pluginStatusDescriptor = [NSSortDescriptor(keyPath: \StorageSitePlugin.status, ascending: true)]

return ResultsController(storageManager: storageManager,
matching: sitePredicate,
sortedBy: pluginStatusDescriptor)
}

func observeStoreSwitch() {
pluginResultsController = updatePluginResultsController()
do {
try pluginResultsController.performFetch()
} catch {
DDLogError("ZendeskManager: Unable to update plugin results")
}
}

/// IPP plugin statuses
///
private var ippPluginstatuses: [String] {
var ippTags = [PluginStatus]()
if let stripe = pluginResultsController.fetchedObjects.first(where: { $0.plugin == PluginSlug.stripe }) {
if stripe.status == .active {
ippTags.append(.stripeInstalledAndActivated)
} else if stripe.status == .inactive {
ippTags.append(.stripeInstalledButNotActivated)
}
} else {
ippTags.append(.stripeNotInstalled)
}
if let wcpay = pluginResultsController.fetchedObjects.first(where: { $0.plugin == PluginSlug.wcpay }) {
if wcpay.status == .active {
ippTags.append(.wcpayInstalledAndActivated)
} else if wcpay.status == .inactive {
ippTags.append(.wcpayInstalledButNotActivated)
}
}
else {
ippTags.append(.wcpayNotInstalled)
}
return ippTags.map { $0.rawValue }
}

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


/// Designated Initialier
///
fileprivate override init() {
super.init()
try? pluginResultsController.performFetch()
observeZendeskNotifications()
}

Expand Down Expand Up @@ -324,8 +386,7 @@ 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]

let tags = [Constants.platformTag, Constants.sdkTag, Constants.jetpackTag] + ippPluginstatuses
return decorateTags(tags: tags, supportSourceTag: supportSourceTag)
}

Expand Down Expand Up @@ -1066,6 +1127,20 @@ private extension ZendeskManager {
}
}

private extension ZendeskManager {
enum PluginSlug {
static let stripe = "woocommerce-gateway-stripe/woocommerce-gateway-stripe"
static let wcpay = "woocommerce-payments/woocommerce-payments"
}
enum PluginStatus: String {
case stripeNotInstalled = "woo_mobile_stripe_not_installed"
case stripeInstalledAndActivated = "woo_mobile_stripe_installed_and_activated"
case stripeInstalledButNotActivated = "woo_mobile_stripe_installed_and_not_activated"
case wcpayNotInstalled = "woo_mobile_wcpay_not_installed"
case wcpayInstalledAndActivated = "woo_mobile_wcpay_installed_and_activated"
case wcpayInstalledButNotActivated = "woo_mobile_wcpay_installed_and_not_activated"
}
}

// MARK: - UITextFieldDelegate
//
Expand Down
4 changes: 4 additions & 0 deletions WooCommerce/WooCommerceTests/Testing/MockZendeskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ final class MockZendeskManager: ZendeskManagerProtocol {
func reset() {
// no-op
}

func observeStoreSwitch() {
// no-op
}
}

extension MockZendeskManager: SupportManagerAdapter {
Expand Down