@@ -72,12 +72,6 @@ class NotificationsViewController: UIViewController {
7272 return resultsController. isEmpty
7373 }
7474
75- /// Returns a collection of every Unreead Notification
76- ///
77- private var unreadNotes : [ Note ] {
78- return resultsController. fetchedObjects. filter { $0. read == false }
79- }
80-
8175
8276 // MARK: - View Lifecycle
8377
@@ -177,16 +171,14 @@ private extension NotificationsViewController {
177171 }
178172
179173 @IBAction func markAllAsRead( ) {
180- let identifiers = unreadNotes . map { $0. noteId }
181- guard identifiers . isEmpty == false else {
174+ let unread = resultsController . fetchedObjects . filter { $0. read == false }
175+ if unread . isEmpty {
182176 DDLogVerbose ( " # Every single notification is already marked as Read! " )
183177 return
184178 }
185179
186- hapticGenerator . prepare ( )
180+ markAsRead ( notes : unread )
187181 hapticGenerator. notificationOccurred ( . success)
188-
189- markAsRead ( identifiers: identifiers)
190182 }
191183}
192184
@@ -195,31 +187,32 @@ private extension NotificationsViewController {
195187//
196188private extension NotificationsViewController {
197189
198- /// Synchronizes the Notifications associated to the active WordPress.com account .
190+ /// Marks the specified collection of Notifications as Read .
199191 ///
200- func synchronizeNotifications( onCompletion: ( ( ) -> Void ) ? = nil ) {
201- let action = NotificationAction . synchronizeNotifications { error in
192+ func markAsRead( notes: [ Note ] ) {
193+ let identifiers = notes. map { $0. noteId }
194+ let action = NotificationAction . updateMultipleReadStatus ( noteIds: identifiers, read: true ) { error in
202195 if let error = error {
203- DDLogError ( " ⛔️ Error synchronizing notifications: \( error) " )
196+ DDLogError ( " ⛔️ Error marking notifications as read : \( error) " )
204197 }
205-
206- self . transitionToResultsUpdatedState ( )
207- onCompletion ? ( )
208198 }
209199
210- transitionToSyncingState ( )
211200 StoresManager . shared. dispatch ( action)
212201 }
213202
214- /// Marks the specified collection of Notifications as Read .
203+ /// Synchronizes the Notifications associated to the active WordPress.com account .
215204 ///
216- func markAsRead ( identifiers : [ Int64 ] ) {
217- let action = NotificationAction . updateMultipleReadStatus ( noteIds : identifiers , read : true ) { error in
205+ func synchronizeNotifications ( onCompletion : ( ( ) -> Void ) ? = nil ) {
206+ let action = NotificationAction . synchronizeNotifications { error in
218207 if let error = error {
219- DDLogError ( " ⛔️ Error marking notifications as read : \( error) " )
208+ DDLogError ( " ⛔️ Error synchronizing notifications: \( error) " )
220209 }
210+
211+ self . transitionToResultsUpdatedState ( )
212+ onCompletion ? ( )
221213 }
222214
215+ transitionToSyncingState ( )
223216 StoresManager . shared. dispatch ( action)
224217 }
225218}
0 commit comments