@@ -296,7 +296,7 @@ func (a *App) getCleanedCalendar(all []byte, hiddenCourses map[string]bool) (*ic
296296 }
297297 }
298298
299- // Second pass: deduplicate and clean events, adding additional rooms to description
299+ // Second pass: deduplicate and clean events, adding additional rooms to the description
300300 hasLecture := make (map [string ]bool )
301301 var newComponents []ics.Component // saves the components we keep because they are not duplicated
302302
@@ -378,20 +378,12 @@ var reRoom = regexp.MustCompile("^(.*?),.*?(\\d{4})\\.(?:\\d\\d|EG|UG|DG|Z\\d|U\
378378var reNavigaTUM = regexp .MustCompile ("\\ (\\ d{4}\\ .[a-zA-Z0-9]{2}\\ .\\ d{3}[A-Z]?\\ )" )
379379
380380func (a * App ) cleanEvent (event * ics.VEvent , additionalLocations []string ) {
381+ // Event Title
381382 summary := ""
382383 if s := event .GetProperty (ics .ComponentPropertySummary ); s != nil {
383384 summary = cleanEventSummary (s .Value )
384385 }
385-
386- description := ""
387- if d := event .GetProperty (ics .ComponentPropertyDescription ); d != nil {
388- description = d .Value
389- }
390-
391- location := ""
392- if l := event .GetProperty (ics .ComponentPropertyLocation ); l != nil {
393- location = event .GetProperty (ics .ComponentPropertyLocation ).Value
394- }
386+ originalSummary := summary
395387
396388 // Remove the TAG and anything after e.g.: (IN0001) or [MA0001]
397389 summary = reTag .ReplaceAllString (summary , "" )
@@ -405,11 +397,26 @@ func (a *App) cleanEvent(event *ics.VEvent, additionalLocations []string) {
405397 // What the heck? And why only sometimes???
406398 summary = reWeirdStartingNumbers .ReplaceAllString (summary , "" )
407399
400+ // Do all the course-specific replacements
401+ for _ , repl := range a .courseReplacements {
402+ summary = strings .ReplaceAll (summary , repl .key , repl .value )
403+ }
408404 event .SetSummary (summary )
409405
406+ // Description
410407 // Remember the old title in the description
411- description = summary + "\n " + description
408+ description := ""
409+ if d := event .GetProperty (ics .ComponentPropertyDescription ); d != nil {
410+ description = d .Value
411+ }
412+ description = originalSummary + "\n " + description
412413
414+ // Location
415+ // Replace the location with the building name, if it matches our map
416+ location := ""
417+ if l := event .GetProperty (ics .ComponentPropertyLocation ); l != nil {
418+ location = event .GetProperty (ics .ComponentPropertyLocation ).Value
419+ }
413420 results := reRoom .FindStringSubmatch (location )
414421 if len (results ) == 3 {
415422 if building , ok := a .buildingReplacements [results [2 ]]; ok {
@@ -428,14 +435,9 @@ func (a *App) cleanEvent(event *ics.VEvent, additionalLocations []string) {
428435 if len (additionalLocations ) > 0 {
429436 description = "Additional rooms:\n " + strings .Join (additionalLocations , "\n " ) + "\n \n " + description
430437 }
431-
432438 event .SetDescription (description )
433439
434- // set title on summary:
435- for _ , repl := range a .courseReplacements {
436- summary = strings .ReplaceAll (summary , repl .key , repl .value )
437- }
438- event .SetSummary (summary )
440+ // Set status based on ical status, so cancelled events are marked as such in the calendar
439441 switch event .GetProperty (ics .ComponentPropertyStatus ).Value {
440442 case "CONFIRMED" :
441443 event .SetStatus (ics .ObjectStatusConfirmed )
0 commit comments