Skip to content

Commit 289fc50

Browse files
authored
Merge pull request #590 from woocommerce/fix/563-mark-as-read-notice
Reapply updates from "marked as read" notice PR (#579)
2 parents cc86183 + 903f155 commit 289fc50

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

WooCommerce/Classes/Extensions/UserDefaults+Woo.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension UserDefaults {
1717
case versionOfLastRun
1818
case analyticsUsername
1919
case notificationsLastSeenTime
20+
case notificationsMarkAsReadCount
2021
}
2122
}
2223

WooCommerce/Classes/ViewRelated/Notifications/NotificationsViewController.swift

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ class NotificationsViewController: UIViewController {
122122
}
123123
}
124124

125+
/// The number of times the "Mark all as read" button was tapped
126+
///
127+
private var markAsReadCount: Int {
128+
get {
129+
return UserDefaults.standard.integer(forKey: UserDefaults.Key.notificationsMarkAsReadCount.rawValue)
130+
}
131+
set {
132+
return UserDefaults.standard[.notificationsMarkAsReadCount] = newValue
133+
}
134+
}
135+
125136
// MARK: - View Lifecycle
126137

127138
deinit {
@@ -252,7 +263,6 @@ private extension NotificationsViewController {
252263
}
253264

254265
markAsRead(notes: unreadNotes)
255-
hapticGenerator.notificationOccurred(.success)
256266
}
257267

258268
@IBAction func displayFiltersAlert() {
@@ -350,7 +360,11 @@ private extension NotificationsViewController {
350360
let identifiers = notes.map { $0.noteId }
351361
let action = NotificationAction.updateMultipleReadStatus(noteIds: identifiers, read: true) { [weak self] error in
352362
if let error = error {
353-
DDLogError("⛔️ Error marking notifications as read: \(error)")
363+
DDLogError("⛔️ Error marking multiple notifications as read: \(error)")
364+
self?.hapticGenerator.notificationOccurred(.error)
365+
} else {
366+
self?.hapticGenerator.notificationOccurred(.success)
367+
self?.displayMarkAllAsReadNoticeIfNeeded()
354368
}
355369
self?.updateMarkAllReadButtonState()
356370
}
@@ -785,6 +799,20 @@ private extension NotificationsViewController {
785799
func updateMarkAllReadButtonState() {
786800
leftBarButton.isEnabled = !unreadNotes.isEmpty
787801
}
802+
803+
/// Displays the `Mark all as read` Notice if the number of times it was previously displayed is lower than the
804+
/// `Settings.markAllAsReadNoticeMaxViews` value.
805+
///
806+
func displayMarkAllAsReadNoticeIfNeeded() {
807+
guard markAsReadCount < Settings.markAllAsReadNoticeMaxViews else {
808+
return
809+
}
810+
811+
markAsReadCount += 1
812+
let message = NSLocalizedString("All notifications marked as read", comment: "Mark all notifications as read notice")
813+
let notice = Notice(title: message, feedbackType: .success)
814+
AppDelegate.shared.noticePresenter.enqueue(notice: notice)
815+
}
788816
}
789817

790818

@@ -816,8 +844,9 @@ private extension NotificationsViewController {
816844
}
817845

818846
enum Settings {
819-
static let estimatedRowHeight = CGFloat(88)
820-
static let placeholderRowsPerSection = [3]
847+
static let estimatedRowHeight = CGFloat(88)
848+
static let placeholderRowsPerSection = [3]
849+
static let markAllAsReadNoticeMaxViews = 2
821850
}
822851

823852
enum State {

0 commit comments

Comments
 (0)