@@ -54,14 +54,15 @@ public PersonalCalendarContext(PersonalCalendarContextDto dto)
5454 AddOriginalEvents ( calendar , calendar . Events ) ;
5555
5656 foreach ( var modification in config . Modifications )
57- foreach ( var eventContext in modification . Target . GetTargets ( _targetIndex ) )
58- eventContext . AddModification ( modification ) ;
57+ foreach ( var eventContext in modification . Target . GetTargets ( _targetIndex ) )
58+ eventContext . AddModification ( modification ) ;
5959
6060 foreach ( var eventIndexEntry in _eventsByStart )
6161 IndexModifiedEvent ( eventIndexEntry . EventContext ) ;
6262 }
6363
64- private List < EventContext > AddOriginalEvents ( PersonalCalendarLive sourceCalendar , IEnumerable < PersonalCalendarEvent > events )
64+ private List < EventContext > AddOriginalEvents ( PersonalCalendarLive sourceCalendar ,
65+ IEnumerable < PersonalCalendarEvent > events )
6566 {
6667 List < EventContext > results = [ ] ;
6768 foreach ( PersonalCalendarEvent originalEvent in events )
@@ -90,22 +91,22 @@ public void ReplaceOriginalEvents(PersonalCalendarLive sourceCalendar, IEnumerab
9091 foreach ( EventContext oldContext in oldContexts )
9192 {
9293 DeindexModifiedEvent ( oldContext ) ;
93-
94+
9495 var originalEvent = oldContext . OriginalEvent ;
9596 _eventsByStart . Remove ( new ( originalEvent . Start , originalEvent . Id , oldContext ) ) ;
9697 _eventsByEnd . Remove ( new ( originalEvent . End , originalEvent . Id , oldContext ) ) ;
9798 _calIdToEvents . RemoveFromCollection ( sourceCalendar . Id , oldContext ) ;
9899 _calAndIdToEvent . Remove ( ( sourceCalendar . Id , originalEvent . Id ) ) ;
99100 _targetIndex . Remove ( oldContext ) ;
100101 }
101-
102+
102103 var newContexts = AddOriginalEvents ( sourceCalendar , events ) ;
103104 TargetIndex tempIndex = new ( ) ;
104105 foreach ( var eventContext in newContexts )
105106 tempIndex . Add ( eventContext ) ;
106107 foreach ( var modification in _modifications )
107- foreach ( var affectedEvent in modification . Target . GetTargets ( tempIndex ) )
108- affectedEvent . AddModification ( modification ) ;
108+ foreach ( var affectedEvent in modification . Target . GetTargets ( tempIndex ) )
109+ affectedEvent . AddModification ( modification ) ;
109110 foreach ( var eventContext in newContexts )
110111 IndexModifiedEvent ( eventContext ) ;
111112 }
@@ -171,15 +172,16 @@ public EventEditContext GetEditContext(int calendarId, string eventId)
171172 var e = _calAndIdToEvent [ ( cal . Id , eventId ) ] ;
172173 var time = e . OriginalEvent . Start . InZone ( SharedUtils . HungarianTimeZone ) ;
173174
174- List < EventContext > ? relatedEvents = null ;
175- if ( e . OriginalEvent is { Subject : { } subject , Course : { } course } )
175+ return new ( e , GetRelatedEvents ( ) ) ;
176+
177+ IRelatedEvents ? GetRelatedEvents ( )
176178 {
177- relatedEvents = _targetIndex . SeriesToEvents [ new ( new ( subject , course ) , time . DayOfWeek , time . TimeOfDay ) ]
178- . Select ( x => x . EventContext )
179- . ToList ( ) ;
179+ if ( e . OriginalEvent is { Subject : { } subject , Course : { } course }
180+ && _targetIndex . SeriesToEvents [ new ( new ( subject , course ) , time . DayOfWeek , time . TimeOfDay ) ]
181+ is { Count : > 1 } entries )
182+ return new NeptunSeriesEvents ( entries . Select ( x => x . EventContext ) . ToList ( ) , new ( subject , course ) ) ;
183+ return null ;
180184 }
181-
182- return new ( e , relatedEvents ) ;
183185 }
184186
185187 public void AddModification ( Modification modification )
@@ -209,13 +211,14 @@ public void AddModification(Modification modification)
209211 }
210212 }
211213
212- public void RevertModifications ( IModificationTarget target , Type actionType )
214+ public void ResetModifications ( IModificationTarget target , Type actionType )
213215 {
214216 var targetEvents = target . GetTargets ( _targetIndex ) ;
215217 foreach ( var eventContext in targetEvents )
216218 {
219+ var modification = eventContext . Modifications . FirstOrDefault ( m => m . Action . GetType ( ) == actionType ) ;
220+ if ( modification is null ) continue ;
217221 DeindexModifiedEvent ( eventContext ) ;
218- var modification = eventContext . Modifications . First ( m => m . Action . GetType ( ) == actionType ) ;
219222 eventContext . RemoveModification ( modification ) ;
220223 if ( modification . Target . RemoveTarget ( eventContext ) )
221224 _modifications . Remove ( modification ) ;
@@ -260,7 +263,14 @@ public int CompareTo(EventIndexEntry other)
260263 }
261264}
262265
263- public record EventEditContext ( EventContext EventContext , List < EventContext > ? RelatedEvents ) ;
266+ public record EventEditContext ( EventContext EventContext , IRelatedEvents ? RelatedEvents ) ;
267+
268+ public interface IRelatedEvents
269+ {
270+ List < EventContext > Events { get ; }
271+ }
272+
273+ public record NeptunSeriesEvents ( List < EventContext > Events , NeptunSubjectAndCourse SubjectAndCourse ) : IRelatedEvents ;
264274
265275public readonly record struct NeptunSubjectAndCourse ( string Subject , string Course ) ;
266276
0 commit comments