1010using CodeHub . Core . ViewModels . PullRequests ;
1111using GitHubSharp . Models ;
1212using CodeHub . Core . Messages ;
13+ using System . Collections . Generic ;
1314
1415namespace CodeHub . Core . ViewModels
1516{
@@ -54,12 +55,12 @@ public ICommand ReadCommand
5455
5556 public ICommand ReadRepositoriesCommand
5657 {
57- get { return _readReposCommand ?? ( _readReposCommand = new MvxCommand < string > ( MarkRepoAsRead ) ) ; }
58+ get { return _readReposCommand ?? ( _readReposCommand = new MvxCommand < string > ( x => MarkRepoAsRead ( x ) ) ) ; }
5859 }
5960
6061 public ICommand ReadAllCommand
6162 {
62- get { return _readAllCommand ?? ( _readAllCommand = new MvxCommand ( MarkAllAsRead , ( ) => ShownIndex != 2 && ! IsLoading && ! IsMarking && Notifications . Any ( ) ) ) ; }
63+ get { return _readAllCommand ?? ( _readAllCommand = new MvxCommand ( ( ) => MarkAllAsRead ( ) , ( ) => ShownIndex != 2 && ! IsLoading && ! IsMarking && Notifications . Any ( ) ) ) ; }
6364 }
6465
6566 public ICommand GoToNotificationCommand
@@ -125,60 +126,45 @@ private async void Read(NotificationModel model)
125126 // If its already read, ignore it
126127 if ( ! model . Unread )
127128 return ;
128-
129- var response = await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Notifications [ model . Id ] . MarkAsRead ( ) ) ;
130- if ( response . Data )
131- {
132- //We just read it
133- model . Unread = false ;
134-
135- //Update the notifications count on the account
136- Notifications . Items . Remove ( model ) ;
137- UpdateAccountNotificationsCount ( ) ;
138- }
139- }
140-
141- private async void MarkRepoAsRead ( string repo )
142- {
143- var items = Notifications . Items . Where ( x => string . Equals ( x . Repository . FullName , repo , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
144-
145129 try
146130 {
147- IsMarking = true ;
148-
149- foreach ( var notification in items )
150- {
151- try
152- {
153- await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Notifications [ notification . Id ] . MarkAsRead ( ) ) ;
154- notification . Unread = false ;
155- }
156- catch
157- {
158- //Ignore?
159- }
160- }
161-
162- Notifications . Items . RemoveRange ( items ) ;
163- UpdateAccountNotificationsCount ( ) ;
131+ var response = await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Notifications [ model . Id ] . MarkAsRead ( ) ) ;
132+ if ( response . Data )
133+ {
134+ //We just read it
135+ model . Unread = false ;
136+
137+ //Update the notifications count on the account
138+ Notifications . Items . Remove ( model ) ;
139+ UpdateAccountNotificationsCount ( ) ;
140+ }
164141 }
165- finally
142+ catch ( Exception e )
166143 {
167- IsMarking = false ;
168- }
144+ ReportError ( e ) ;
145+ }
146+ }
147+
148+ private async Task MarkRepoAsRead ( string repo )
149+ {
150+ var items = Notifications . Items . Where ( x => string . Equals ( x . Repository . FullName , repo , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
151+ await MarkNotificationsAsRead ( items ) ;
169152 }
170153
171- private async void MarkAllAsRead ( )
154+ private async Task MarkAllAsRead ( )
172155 {
173156 // Make sure theres some sort of notification
174- if ( ! Notifications . Any ( ) )
175- return ;
157+ if ( Notifications . Any ( ) )
158+ await MarkNotificationsAsRead ( Notifications ) ;
159+ }
176160
161+ private async Task MarkNotificationsAsRead ( IEnumerable < NotificationModel > notifications )
162+ {
177163 try
178164 {
179165 IsMarking = true ;
180166
181- foreach ( var notification in Notifications )
167+ foreach ( var notification in notifications )
182168 {
183169 try
184170 {
@@ -194,11 +180,15 @@ private async void MarkAllAsRead()
194180 Notifications . Items . Clear ( ) ;
195181 UpdateAccountNotificationsCount ( ) ;
196182 }
183+ catch ( Exception e )
184+ {
185+ ReportError ( e ) ;
186+ }
197187 finally
198188 {
199189 IsMarking = false ;
200190 }
201- }
191+ }
202192
203193 private void UpdateAccountNotificationsCount ( )
204194 {
0 commit comments