@@ -167,6 +167,31 @@ class NativeEventObserver {
167167 }
168168}
169169
170+ @available ( iOS 15 . 0 , * )
171+ func tokenSetsAreEqual< T> (
172+ tokenSetOne: Set < Token < T > > ? ,
173+ tokenSetTwo: Set < Token < T > >
174+ ) -> Bool {
175+ if tokenSetOne == tokenSetTwo {
176+ return true
177+ }
178+
179+ if let tokenSetOne = tokenSetOne {
180+ if tokenSetOne. count == tokenSetTwo. count {
181+ if tokenSetOne. count == 0 {
182+ return true
183+ }
184+ return tokenSetOne. allSatisfy { token in
185+ tokenSetTwo. contains ( token)
186+ }
187+ }
188+ } else {
189+ return tokenSetTwo. isEmpty
190+ }
191+
192+ return false
193+ }
194+
170195@available ( iOS 15 . 0 , * )
171196public class ReactNativeDeviceActivityModule : Module {
172197
@@ -501,33 +526,30 @@ public class ReactNativeDeviceActivityModule: Module {
501526 let selection = deserializeFamilyActivitySelection (
502527 familyActivitySelectionStr: familyActivitySelectionStr)
503528
504- let areAnyApplicationsEqual =
505- store. shield. applications? . map ( { token in
506- token
507- } )
508- == selection. applicationTokens. map ( { token in
509- token
510- } )
511- let areAnyWebDomainsEqual =
512- store. shield. webDomains? . map ( { token in
513- token
514- } )
515- == selection. webDomainTokens. map ( { token in
516- token
517- } )
529+ let shield = store. shield
530+
531+ let areApplicationsEqual = tokenSetsAreEqual (
532+ tokenSetOne: shield. applications,
533+ tokenSetTwo: selection. applicationTokens
534+ )
535+
536+ let areWebDomainsEqual = tokenSetsAreEqual (
537+ tokenSetOne: shield. webDomains,
538+ tokenSetTwo: selection. webDomainTokens
539+ )
518540
519541 let appCategoryPolicy = ShieldSettings . ActivityCategoryPolicy< Application> . specific(
520542 selection. categoryTokens, except: Set ( ) )
521543
522- let areAnyApplicationCategoriesEqual = store . shield. applicationCategories == appCategoryPolicy
544+ let areAnyApplicationCategoriesEqual = shield. applicationCategories == appCategoryPolicy
523545
524546 let webDomainCategoryPolicy = ShieldSettings . ActivityCategoryPolicy< WebDomain> . specific(
525547 selection. categoryTokens, except: Set ( ) )
526548
527549 let areAnyWebDomainCategoriesEqual =
528- webDomainCategoryPolicy == store . shield. webDomainCategories
550+ webDomainCategoryPolicy == shield. webDomainCategories
529551
530- return areAnyApplicationsEqual && areAnyWebDomainsEqual && areAnyApplicationCategoriesEqual
552+ return areApplicationsEqual && areWebDomainsEqual && areAnyApplicationCategoriesEqual
531553 && areAnyWebDomainCategoriesEqual
532554 }
533555
0 commit comments