3030using System . Drawing ;
3131using System . Windows . Forms ;
3232using System . Linq ;
33+ using System . Diagnostics ;
3334
3435//TODO indicate number of never read notifications
3536
@@ -45,11 +46,12 @@ namespace ORTS
4546 public class NotificationManager
4647 {
4748 public bool ArePagesVisible = false ;
48- // New notifications are those with a date after the NotificationsReadDate.
49+
4950 // Notifications are listed in reverse date order, with the newest one at the front.
50- // We don't track the reading of each notification but set the NewNotificationCount = 0 after the last of the new ones has been read.
51- public int NewPageCount = 1 ;
52- public int LastPageViewed = 0 ;
51+ // We track the reading of each new notification but set the NewPageCount = 0 after the last of the new ones has been read.
52+ public string LastViewDate ; // This is the date when notifications were last viewed and is saved in yyyy-MM-dd format as a hidden UserSetting.
53+ public int NewPageCount ; // New notifications are those with a date after the LastViewDate.
54+ public int NewPagesViewed ; // Viewing always starts at the first, newest notification. The user sees (NewPageCount - NewpagesViewed)
5355
5456 public Notifications Notifications ; // An object defined by the JSON schema
5557 public int CurrentNotificationNo = 0 ;
@@ -140,6 +142,11 @@ public Notifications GetNotifications()
140142 var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling . Auto } ;
141143 var jsonInput = JsonConvert . DeserializeObject < Notifications > ( notificationsSerial , jsonSettings ) ;
142144
145+ NewPageCount = 0 ;
146+ NewPagesViewed = 0 ;
147+ LastViewDate = Settings . LastViewNotificationDate ;
148+ if ( LastViewDate == "" ) LastViewDate = "2024-01-01" ; // Date of this code - i.e. before Notifications went public
149+
143150 //TODO Cache jsonInput
144151
145152 return jsonInput ;
@@ -164,12 +171,19 @@ private string GetRemoteJson()
164171
165172 private List < Notification > IncludeValid ( List < Notification > list )
166173 {
174+ NewPageCount = 0 ;
175+
167176 var filteredList = new List < Notification > ( ) ;
168177 foreach ( var n in list )
169178 {
170179 if ( AreNotificationChecksMet ( n ) )
171180 {
172- if ( n . Date == "none" ) n . Date = " none" ; // UpdateChannel = "none" found; push this to end of the list
181+ if ( n . Date == "none" )
182+ n . Date = " none" ; // UpdateChannel = "none" found; push this to end of the list
183+ else
184+ {
185+ if ( String . Compare ( LastViewDate , n . Date ) == - 1 ) NewPageCount ++ ;
186+ }
173187 filteredList . Insert ( 0 , n ) ; // Add to head of list to provide a basic pre-sort.
174188 }
175189 }
@@ -186,6 +200,8 @@ private List<Notification> SortByDate(List<Notification> list)
186200 /// </summary>
187201 public void PopulatePage ( )
188202 {
203+ Settings . LastViewNotificationDate = $ "{ DateTime . Today : yyyy-MM-dd} ";
204+ Settings . Save ( "LastViewNotificationDate" ) ; // Saves the date on any viewing of notifications
189205 Page = new NotificationPage ( MainForm , Panel , this ) ;
190206
191207 if ( UpdateManager . LastCheckError != null || Error != null )
@@ -209,7 +225,6 @@ public void PopulatePage()
209225 Page . NDetailList . Add ( new NRetryControl ( Page , "Retry" , 140 , "Try again to fetch notifications" , MainForm ) ) ;
210226 }
211227
212- NewPageCount = 1 ;
213228 var list = Notifications . NotificationList ;
214229 var n = list [ CurrentNotificationNo ] ;
215230 LogNotification ( n ) ;
@@ -590,7 +605,12 @@ public OverrideParameterList GetOverrideParameters()
590605 public void ChangePage ( int step )
591606 {
592607 CurrentNotificationNo += step ;
593- //SetVisibility(step);
608+ if ( step > 0
609+ && CurrentNotificationNo > NewPagesViewed // and this is a new unviewed page
610+ && CurrentNotificationNo <= NewPageCount ) // and there are still new unviewed pages to be viewed
611+ {
612+ NewPagesViewed ++ ;
613+ }
594614 MainForm . ShowNotificationPages ( ) ;
595615 }
596616
0 commit comments