- if (oldApt && ([props containsObject: @"organizer"])) {
- uid = [um getUIDForICalPerson:[oldApt organizer]];
- if (uid) {
- if (![storeUIDs containsObject:uid]) {
- if (![removedUIDs containsObject:uid]) {
- [removedUIDs addObject:uid];
- }
- }
- }
- }
-
- [self debugWithFormat:@"UID ops:\n store: %@\n remove: %@",
- storeUIDs, removedUIDs];
-
- /* if time did change, all participants have to re-decide ...
- * ... exception from that rule: the organizer
- */
-
- if (oldApt != nil &&
- ([props containsObject:@"startDate"] ||
- [props containsObject:@"endDate"] ||
- [props containsObject:@"duration"]))
- {
- NSArray *ps;
- unsigned i, count;
+ /* diff */
+
+ changes = [iCalEventChanges changesFromEvent: oldApt toEvent: newApt];
+ uids = [self getUIDsForICalPersons: [changes deletedAttendees]];
+ removedUIDs = [NSMutableArray arrayWithArray: uids];
+
+ uids = [self getUIDsForICalPersons: [newApt attendees]];
+ storeUIDs = [NSMutableArray arrayWithArray: uids];
+ props = [changes updatedProperties];
+
+ /* detect whether sequence has to be increased */
+ if ([changes hasChanges])
+ [newApt increaseSequence];
+
+ /* preserve organizer */
+
+ organizer = [newApt organizer];
+ uid = [self getUIDForICalPerson: organizer];
+ if (!uid)
+ uid = [self ownerInContext: nil];
+ if (uid)
+ {
+ [storeUIDs addObjectUniquely: uid];
+ [removedUIDs removeObject: uid];
+ }
+
+ /* organizer might have changed completely */
+
+ if (oldApt && ([props containsObject: @"organizer"]))
+ {
+ uid = [self getUIDForICalPerson: [oldApt organizer]];
+ if (uid && ![storeUIDs containsObject: uid])
+ [removedUIDs addObjectUniquely: uid];
+ }
+
+ [self debugWithFormat: @"UID ops:\n store: %@\n remove: %@",
+ storeUIDs, removedUIDs];
+
+ /* if time did change, all participants have to re-decide ...
+ * ... exception from that rule: the organizer
+ */
+
+ if (oldApt
+ && ([props containsObject: @"startDate"]
+ || [props containsObject: @"endDate"]
+ || [props containsObject: @"duration"]))
+ {
+ NSArray *ps;
+ unsigned i, count;