From b88d623ad373eb65e577afd111b91bc655b3b86a Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 20 Jun 2012 14:05:40 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: b532b841f572a64aa9b471da32a51bb939539334 Monotone-Revision: 7658ec99af152b2743393d20c3c4f2c23610ec4c Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2012-06-20T14:05:40 --- ChangeLog | 7 +++ .../Appointments/SOGoAppointmentObject.m | 50 +++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8be121787..42d2499d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-06-20 Ludovic Marcotte + + * SoObjects/Appointments/SOGoAppointmentObject.m + (-_handleResourcesConflicts:forEvent:): We now + handle correctly recurring events overlapping other + recurring events. + 2012-06-19 Ludovic Marcotte * SoObjects/Appointments/SOGoAppointmentFolder.m (-importCalendar:): diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index 596e2d2ba..e85bdeec0 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2011 Inverse inc. + Copyright (C) 2007-2012 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of SOGo @@ -456,8 +456,12 @@ { SOGoAppointmentFolder *folder; NSCalendarDate *start, *end; + NGCalendarDateRange *range; NSMutableArray *fbInfo; - int i; + NSArray *allOccurences; + + BOOL must_delete; + int i, j; // We get the start/end date for our conflict range. If the event to be added is recurring, we // check for at least a year to start with. @@ -486,12 +490,50 @@ // We first remove any occurences in the freebusy that corresponds to the // current event. We do this to avoid raising a conflict if we move a 1 hour // meeting from 12:00-13:00 to 12:15-13:15. We would overlap on ourself otherwise. + // + // We must also check here for repetitive events that don't overlap our event. + // We remove all events that don't overlap. The events here are already + // decomposed. + // + if ([theEvent isRecurrent]) + allOccurences = [theEvent recurrenceRangesWithinCalendarDateRange: [NGCalendarDateRange calendarDateRangeWithStartDate: start + endDate: end] + firstInstanceCalendarDateRange: [NGCalendarDateRange calendarDateRangeWithStartDate: [theEvent startDate] + endDate: [theEvent endDate]]]; + else + allOccurences = nil; + for (i = [fbInfo count]-1; i >= 0; i--) { + range = [NGCalendarDateRange calendarDateRangeWithStartDate: [[fbInfo objectAtIndex: i] objectForKey: @"startDate"] + endDate: [[fbInfo objectAtIndex: i] objectForKey: @"endDate"]]; + if ([[[fbInfo objectAtIndex: i] objectForKey: @"c_uid"] compare: [theEvent uid]] == NSOrderedSame) - [fbInfo removeObjectAtIndex: i]; - } + { + [fbInfo removeObjectAtIndex: i]; + continue; + } + + // No need to check if the event isn't recurrent here as it's handled correctly + // when we compute the "end" date. + if ([allOccurences count]) + { + must_delete = YES; + for (j = 0; j < [allOccurences count]; j++) + { + if ([range doesIntersectWithDateRange: [allOccurences objectAtIndex: j]]) + { + must_delete = NO; + break; + } + } + + if (must_delete) + [fbInfo removeObjectAtIndex: i]; + } + } + if ([fbInfo count]) { // If we always force the auto-accept if numberOfSimultaneousBookings == 0 (ie., no limit