@@ -9,7 +9,6 @@ import CoreTelephony
99import SafariServices
1010import Yosemite
1111
12-
1312extension NSNotification . Name {
1413 static let ZDPNReceived = NSNotification . Name ( rawValue: " ZDPNReceived " )
1514 static let ZDPNCleared = NSNotification . Name ( rawValue: " ZDPNCleared " )
@@ -23,6 +22,8 @@ extension NSNotification.Name {
2322protocol ZendeskManagerProtocol : SupportManagerAdapter {
2423 typealias onUserInformationCompletion = ( _ success: Bool , _ email: String ? ) -> Void
2524
25+ func observeStoreSwitch( )
26+
2627 /// Displays the Zendesk New Request view from the given controller, for users to submit new tickets.
2728 ///
2829 func showNewRequestIfPossible( from controller: UIViewController , with sourceTag: String ? )
@@ -45,6 +46,10 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
4546}
4647
4748struct NoZendeskManager : ZendeskManagerProtocol {
49+ func observeStoreSwitch( ) {
50+ // no-op
51+ }
52+
4853 func showNewRequestIfPossible( from controller: UIViewController ) {
4954 // no-op
5055 }
@@ -138,6 +143,65 @@ struct ZendeskProvider {
138143///
139144#if !targetEnvironment(macCatalyst)
140145final class ZendeskManager : NSObject , ZendeskManagerProtocol {
146+ private let stores = ServiceLocator . stores
147+ private let storageManager = ServiceLocator . storageManager
148+
149+ /// Controller for fetching site plugins from Storage
150+ ///
151+ private lazy var pluginResultsController : ResultsController < StorageSitePlugin > = createPluginResultsController ( )
152+
153+ /// Returns a `pluginResultsController` using the latest selected site ID for predicate
154+ ///
155+ private func createPluginResultsController( ) -> ResultsController < StorageSitePlugin > {
156+ var sitePredicate : NSPredicate ? = nil
157+ if let siteID = stores. sessionManager. defaultSite? . siteID {
158+ sitePredicate = NSPredicate ( format: " siteID == %lld " , siteID)
159+ } else {
160+ DDLogError ( " ZendeskManager: No siteID found when attempting to initialize Plugins Results predicate. " )
161+ }
162+
163+ let pluginStatusDescriptor = [ NSSortDescriptor ( keyPath: \StorageSitePlugin . status, ascending: true ) ]
164+
165+ return ResultsController ( storageManager: storageManager,
166+ matching: sitePredicate,
167+ sortedBy: pluginStatusDescriptor)
168+ }
169+
170+ func observeStoreSwitch( ) {
171+ pluginResultsController = createPluginResultsController ( )
172+ do {
173+ try pluginResultsController. performFetch ( )
174+ } catch {
175+ DDLogError ( " ZendeskManager: Unable to update plugin results " )
176+ }
177+ }
178+
179+ /// List of tags that reflect Stripe and WCPay plugin statuses
180+ ///
181+ private var ippPluginStatuses : [ String ] {
182+ var ippTags = [ PluginStatus] ( )
183+ if let stripe = pluginResultsController. fetchedObjects. first ( where: { $0. plugin == PluginSlug . stripe } ) {
184+ if stripe. status == . active {
185+ ippTags. append ( . stripeInstalledAndActivated)
186+ } else if stripe. status == . inactive {
187+ ippTags. append ( . stripeInstalledButNotActivated)
188+ }
189+ } else {
190+ ippTags. append ( . stripeNotInstalled)
191+ }
192+ if let wcpay = pluginResultsController. fetchedObjects. first ( where: { $0. plugin == PluginSlug . wcpay } ) {
193+ if wcpay. status == . active {
194+ ippTags. append ( . wcpayInstalledAndActivated)
195+ } else if wcpay. status == . inactive {
196+ ippTags. append ( . wcpayInstalledButNotActivated)
197+ }
198+ }
199+ else {
200+ ippTags. append ( . wcpayNotInstalled)
201+ }
202+ return ippTags. map { $0. rawValue }
203+ }
204+
141205 func showNewRequestIfPossible( from controller: UIViewController ) {
142206 showNewRequestIfPossible ( from: controller, with: nil )
143207 }
@@ -185,11 +249,11 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
185249 return ZDKPushProvider ( zendesk: zendesk)
186250 }
187251
188-
189252 /// Designated Initialier
190253 ///
191254 fileprivate override init ( ) {
192255 super. init ( )
256+ try ? pluginResultsController. performFetch ( )
193257 observeZendeskNotifications ( )
194258 }
195259
@@ -324,8 +388,7 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
324388 /// The SDK tag is used in a trigger and displays tickets in Woo > Mobile Apps New.
325389 ///
326390 func getTags( supportSourceTag: String ? ) -> [ String ] {
327- let tags = [ Constants . platformTag, Constants . sdkTag, Constants . jetpackTag]
328-
391+ let tags = [ Constants . platformTag, Constants . sdkTag, Constants . jetpackTag] + ippPluginStatuses
329392 return decorateTags ( tags: tags, supportSourceTag: supportSourceTag)
330393 }
331394
@@ -1066,6 +1129,20 @@ private extension ZendeskManager {
10661129 }
10671130}
10681131
1132+ private extension ZendeskManager {
1133+ enum PluginSlug {
1134+ static let stripe = " woocommerce-gateway-stripe/woocommerce-gateway-stripe "
1135+ static let wcpay = " woocommerce-payments/woocommerce-payments "
1136+ }
1137+ enum PluginStatus : String {
1138+ case stripeNotInstalled = " woo_mobile_stripe_not_installed "
1139+ case stripeInstalledAndActivated = " woo_mobile_stripe_installed_and_activated "
1140+ case stripeInstalledButNotActivated = " woo_mobile_stripe_installed_and_not_activated "
1141+ case wcpayNotInstalled = " woo_mobile_wcpay_not_installed "
1142+ case wcpayInstalledAndActivated = " woo_mobile_wcpay_installed_and_activated "
1143+ case wcpayInstalledButNotActivated = " woo_mobile_wcpay_installed_and_not_activated "
1144+ }
1145+ }
10691146
10701147// MARK: - UITextFieldDelegate
10711148//
0 commit comments