Skip to content

Commit b624f73

Browse files
sla8cstaskus
andauthored
Disable Local Notifications for WeeklyRoundupBackgroundTask for WordPress behind a feature flag (#19590)
* update weeklyRoundup FeatureFlag.swift to be similar to how its handled for bloggingPrompts * remove pending notifications on WordPress when notifications are disabled * update NotificationFilteringService.swift to remove pending notifications when the app is WordPress * WeeklyRoundup Task changes for WordPress app so that a local notification will not be displayed if there was one already scheduled as well as preventing scheduling of future tasks * updated RELEASE-NOTES.txt * logic correction to only cancel pending notifications when we are setting to false * updated FeatureFlag to use NotificationFilteringService * remove call to cancel local notifications - erroneously called from jetpack * update WeeklyRoundupBackgroundTask.swift so that its disabling of the task and notification is determined by the NotificationFilteringService state * Update WordPress/Classes/Services/NotificationFilteringService.swift Co-authored-by: Povilas Staskus <[email protected]> * updated RELEASE-NOTES.txt Co-authored-by: Povilas Staskus <[email protected]>
1 parent e2e9786 commit b624f73

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
21.3
22
-----
3+
* [*] [internal] Weekly roundup notifications and scheduling can be turned off for WordPress as part of Jetpack focus behind a feature flag. [#19590]
34
* [*] Fixed a minor UI issue where the segmented control under My SIte was being clipped when "Home" is selected. [#19595]
45

56
21.2

WordPress/Classes/Services/NotificationFilteringService.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ final class NotificationFilteringService {
2424

2525
set {
2626
userDefaults?.set(newValue, forKey: WPNotificationsEnabledKey)
27+
28+
if isWordPress && !newValue {
29+
cancelAllPendingWordPressLocalNotifications()
30+
}
2731
}
2832
}
2933

@@ -50,9 +54,21 @@ final class NotificationFilteringService {
5054
}
5155

5256
func shouldFilterWordPressNotifications() -> Bool {
53-
return allowDisablingWPNotifications
57+
let shouldFilter = allowDisablingWPNotifications
5458
&& isWordPress
5559
&& !wordPressNotificationsEnabled
60+
61+
if shouldFilter {
62+
cancelAllPendingWordPressLocalNotifications()
63+
}
64+
65+
return shouldFilter
66+
}
67+
68+
private func cancelAllPendingWordPressLocalNotifications(notificationCenter: UNUserNotificationCenter = UNUserNotificationCenter.current()) {
69+
if isWordPress {
70+
notificationCenter.removeAllPendingNotificationRequests()
71+
}
5672
}
5773
}
5874

WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class WeeklyRoundupBackgroundTask: BackgroundTask {
252252
private let eventTracker: NotificationEventTracker
253253
let runDateComponents: DateComponents
254254
let notificationScheduler: WeeklyRoundupNotificationScheduler
255+
private let notificationFilteringService = NotificationFilteringService()
255256

256257
init(
257258
eventTracker: NotificationEventTracker = NotificationEventTracker(),
@@ -260,7 +261,8 @@ class WeeklyRoundupBackgroundTask: BackgroundTask {
260261
store: Store = Store()) {
261262

262263
self.eventTracker = eventTracker
263-
notificationScheduler = WeeklyRoundupNotificationScheduler(staticNotificationDateComponents: staticNotificationDateComponents)
264+
notificationScheduler = WeeklyRoundupNotificationScheduler(staticNotificationDateComponents: staticNotificationDateComponents,
265+
notificationFilteringService: notificationFilteringService)
264266
self.store = store
265267

266268
self.runDateComponents = runDateComponents ?? {
@@ -357,6 +359,14 @@ class WeeklyRoundupBackgroundTask: BackgroundTask {
357359

358360
func run(onError: @escaping (Error) -> Void, completion: @escaping (Bool) -> Void) {
359361

362+
// This will no longer run for WordPress as part of JetPack migration.
363+
// This can be removed once JetPack migration is complete.
364+
if notificationFilteringService.shouldFilterWordPressNotifications() {
365+
notificationScheduler.cancellAll()
366+
notificationScheduler.cancelStaticNotification()
367+
return
368+
}
369+
360370
// We use multiple operations in series so that if the expiration handler is
361371
// called, the operation queue will cancell any pending operations, ensuring
362372
// that the task will exit as soon as possible.
@@ -485,9 +495,11 @@ class WeeklyRoundupNotificationScheduler {
485495

486496
init(
487497
staticNotificationDateComponents: DateComponents? = nil,
498+
notificationFilteringService: NotificationFilteringService,
488499
userNotificationCenter: UNUserNotificationCenter = UNUserNotificationCenter.current()) {
489500

490501
self.userNotificationCenter = userNotificationCenter
502+
self.notificationFilteringService = notificationFilteringService
491503

492504
self.staticNotificationDateComponents = staticNotificationDateComponents ?? {
493505
var dateComponents = DateComponents()
@@ -506,6 +518,7 @@ class WeeklyRoundupNotificationScheduler {
506518

507519
let staticNotificationDateComponents: DateComponents
508520
let userNotificationCenter: UNUserNotificationCenter
521+
let notificationFilteringService: NotificationFilteringService
509522

510523
enum NotificationSchedulingError: Error {
511524
case staticNotificationSchedulingError(error: Error)
@@ -611,6 +624,10 @@ class WeeklyRoundupNotificationScheduler {
611624
dateComponents: DateComponents,
612625
completion: @escaping (Result<Void, Error>) -> Void) {
613626

627+
if notificationFilteringService.shouldFilterWordPressNotifications() {
628+
return
629+
}
630+
614631
let content = UNMutableNotificationContent()
615632
content.title = title
616633
content.body = body
@@ -649,7 +666,7 @@ class WeeklyRoundupNotificationScheduler {
649666
}
650667
}
651668

652-
func cancelStaticNotification(completion: @escaping (Bool) -> Void) {
669+
func cancelStaticNotification(completion: @escaping (Bool) -> Void = { _ in }) {
653670
userNotificationCenter.getPendingNotificationRequests { requests in
654671
if Feature.enabled(.weeklyRoundupStaticNotification) {
655672
guard requests.contains( where: { $0.identifier == self.staticNotificationIdentifier }) else {

WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
7272
case .siteIconCreator:
7373
return BuildConfiguration.current != .appStore
7474
case .weeklyRoundup:
75-
return true
75+
return !NotificationFilteringService().shouldFilterWordPressNotifications()
7676
case .weeklyRoundupStaticNotification:
7777
// This may be removed, but we're feature flagging it for now until we know for sure we won't need it.
7878
return false

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,13 @@
29092909
DCF892CD282FA3BB00BB71E1 /* SiteStatsImmuTableRows.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCF892CB282FA3BB00BB71E1 /* SiteStatsImmuTableRows.swift */; };
29102910
DCF892D0282FA42A00BB71E1 /* SiteStatsImmuTableRowsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCF892CF282FA42A00BB71E1 /* SiteStatsImmuTableRowsTests.swift */; };
29112911
DCF892D2282FA45500BB71E1 /* StatsMockDataLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCF892D1282FA45500BB71E1 /* StatsMockDataLoader.swift */; };
2912+
DCFC6A212924FD780062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
2913+
DCFC6A222924FD790062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
2914+
DCFC6A232924FD790062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
2915+
DCFC6A242924FD7A0062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
2916+
DCFC6A252924FD840062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
2917+
DCFC6A262924FD840062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
2918+
DCFC6A272924FD850062D65B /* NotificationFilteringService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010459E529153FFF000C7778 /* NotificationFilteringService.swift */; };
29122919
DF6D9E10C4CEE05331B4DAE5 /* Pods_WordPressNotificationServiceExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3B8D9C4DCD93C57C2B98CDC /* Pods_WordPressNotificationServiceExtension.framework */; };
29132920
E100C6BB1741473000AE48D8 /* WordPress-11-12.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = E100C6BA1741472F00AE48D8 /* WordPress-11-12.xcmappingmodel */; };
29142921
E10290741F30615A00DAC588 /* Role.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10290731F30615A00DAC588 /* Role.swift */; };
@@ -19623,6 +19630,7 @@
1962319630
0107E0C928F97D5000DE87DB /* SiteListProvider.swift in Sources */,
1962419631
0107E0CA28F97D5000DE87DB /* HomeWidgetThisWeekData.swift in Sources */,
1962519632
0107E0CB28F97D5000DE87DB /* WordPressHomeWidgetAllTime.swift in Sources */,
19633+
DCFC6A272924FD850062D65B /* NotificationFilteringService.swift in Sources */,
1962619634
0107E0CC28F97D5000DE87DB /* KeyValueDatabase.swift in Sources */,
1962719635
0107E0CD28F97D5000DE87DB /* CocoaLumberjack.swift in Sources */,
1962819636
0107E0CE28F97D5000DE87DB /* ListRow.swift in Sources */,
@@ -21395,6 +21403,7 @@
2139521403
3F8B136D25D08F34004FAC0A /* HomeWidgetThisWeekData.swift in Sources */,
2139621404
3F5C86C025CA197500BABE64 /* WordPressHomeWidgetAllTime.swift in Sources */,
2139721405
3F6BC07E25B247A4007369D3 /* KeyValueDatabase.swift in Sources */,
21406+
DCFC6A232924FD790062D65B /* NotificationFilteringService.swift in Sources */,
2139821407
3F1FD27B2548AE900060C53A /* CocoaLumberjack.swift in Sources */,
2139921408
3FCF66FB25CAF8E00047F337 /* ListRow.swift in Sources */,
2140021409
8323789828526E6D003F4443 /* AppConfiguration.swift in Sources */,
@@ -21487,6 +21496,7 @@
2148721496
83A1B19B28AFE47D00E737AC /* KeychainUtils.swift in Sources */,
2148821497
436110DD22C41AFD000773AD /* FeatureFlag.swift in Sources */,
2148921498
436110DC22C41ADB000773AD /* UIColor+MurielColors.swift in Sources */,
21499+
DCFC6A242924FD7A0062D65B /* NotificationFilteringService.swift in Sources */,
2149021500
170BEC8A239153160017AEC1 /* FeatureFlagOverrideStore.swift in Sources */,
2149121501
433ADC1B223B2A7E00ED9DE1 /* TextBundleWrapper.m in Sources */,
2149221502
4326191622FCB9F8003C7642 /* MurielColor.swift in Sources */,
@@ -21616,6 +21626,7 @@
2161621626
74021A00202E12F4006CC39F /* MediaUploadOperation.swift in Sources */,
2161721627
74021A0E202E1358006CC39F /* Tracks.swift in Sources */,
2161821628
74BC35BA20499EEB00AC1525 /* RemotePostCategory+Extensions.swift in Sources */,
21629+
DCFC6A222924FD790062D65B /* NotificationFilteringService.swift in Sources */,
2161921630
74E44AD62031E85A00556205 /* ShareNoticeConstants.swift in Sources */,
2162021631
986FF29D2141971C005B28EC /* WPAnimatedBox.m in Sources */,
2162121632
986FF2A0214198D9005B28EC /* String+Ranges.swift in Sources */,
@@ -21691,6 +21702,7 @@
2169121702
8096210728E540D700940A5D /* FormatBarItemProviders.swift in Sources */,
2169221703
0107E11228FD7FE200DE87DB /* AppConfiguration.swift in Sources */,
2169321704
8096210828E540D700940A5D /* ShareSegueHandler.swift in Sources */,
21705+
DCFC6A252924FD840062D65B /* NotificationFilteringService.swift in Sources */,
2169421706
8096210928E540D700940A5D /* RemotePostCategory+Extensions.swift in Sources */,
2169521707
8096210A28E540D700940A5D /* WPReusableTableViewCells.swift in Sources */,
2169621708
8096210B28E540D700940A5D /* WPAnimatedBox.m in Sources */,
@@ -21766,6 +21778,7 @@
2176621778
8096216828E55C9400940A5D /* Tracks.swift in Sources */,
2176721779
0107E11328FD7FE300DE87DB /* AppConfiguration.swift in Sources */,
2176821780
8096216928E55C9400940A5D /* RemotePostCategory+Extensions.swift in Sources */,
21781+
DCFC6A262924FD840062D65B /* NotificationFilteringService.swift in Sources */,
2176921782
8096216A28E55C9400940A5D /* ShareNoticeConstants.swift in Sources */,
2177021783
8096216B28E55C9400940A5D /* WPAnimatedBox.m in Sources */,
2177121784
8096216C28E55C9400940A5D /* String+Ranges.swift in Sources */,
@@ -21905,6 +21918,7 @@
2190521918
B504F5F51C9C2BD000F8B1C6 /* Tracks+ShareExtension.swift in Sources */,
2190621919
74D06FE81FE076F700AF1788 /* FormatBarItemProviders.swift in Sources */,
2190721920
745EAF452003FD050066F415 /* ShareSegueHandler.swift in Sources */,
21921+
DCFC6A212924FD780062D65B /* NotificationFilteringService.swift in Sources */,
2190821922
74BC35B920499EEB00AC1525 /* RemotePostCategory+Extensions.swift in Sources */,
2190921923
7455836B201A216C007809BB /* WPReusableTableViewCells.swift in Sources */,
2191021924
986FF29E2141971D005B28EC /* WPAnimatedBox.m in Sources */,

0 commit comments

Comments
 (0)