Fix bug 466655 - organizer adds an alarm and/or a category -> notification eMail dialog pops up. r=philipp
authorDaniel Boelzle [:dbo] <daniel.boelzle@sun.com>
Mon, 08 Dec 2008 14:34:09 +0100
changeset 1372 2af9fdc775005f81b915cb580d13664a45efd228
parent 1371 218b182a4ad71d9ad99ac349d4f9b305c684c44e
child 1373 73b79d33f8842159186b17ee1f6ee91c70d9f9ce
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs466655
Fix bug 466655 - organizer adds an alarm and/or a category -> notification eMail dialog pops up. r=philipp
calendar/base/modules/calItipUtils.jsm
--- a/calendar/base/modules/calItipUtils.jsm
+++ b/calendar/base/modules/calItipUtils.jsm
@@ -259,51 +259,55 @@ cal.itip = {
 
             for each (let cancAtt in attMap) {
                 canceledAttendees.push(cancAtt);
             }
         }
 
         // Check to see if some part of the item was updated, if so, re-send REQUEST
         if (!aOriginalItem || (cal.itip.compare(aItem, aOriginalItem) > 0)) { // REQUEST
-            let requestItem = aItem.clone();
 
             // check whether it's a simple UPDATE (no SEQUENCE change) or real (RE)REQUEST,
             // in case of time or location/description change.
             let isMinorUpdate = (aOriginalItem && (cal.itip.getSequence(aItem) == cal.itip.getSequence(aOriginalItem)));
 
-            if (!requestItem.organizer) {
-                let organizer = cal.createAttendee();
-                organizer.id = requestItem.calendar.getProperty("organizerId");
-                organizer.commonName = requestItem.calendar.getProperty("organizerCN");
-                organizer.role = "REQ-PARTICIPANT";
-                organizer.participationStatus = "ACCEPTED";
-                organizer.isOrganizer = true;
-                requestItem.organizer = organizer;
-            }
+            if (!isMinorUpdate || !cal.compareItemContent(stripUserData(aItem), stripUserData(aOriginalItem))) {
+
+                let requestItem = aItem.clone();
+                if (!requestItem.organizer) {
+                    let organizer = cal.createAttendee();
+                    organizer.id = requestItem.calendar.getProperty("organizerId");
+                    organizer.commonName = requestItem.calendar.getProperty("organizerCN");
+                    organizer.role = "REQ-PARTICIPANT";
+                    organizer.participationStatus = "ACCEPTED";
+                    organizer.isOrganizer = true;
+                    requestItem.organizer = organizer;
+                }
 
-            // Fix up our attendees for invitations using some good defaults
-            let recipients = [];
-            let itemAtt = requestItem.getAttendees({});
-            if (!isMinorUpdate) {
-                requestItem.removeAllAttendees();
-            }
-            for each (let attendee in itemAtt) {
+                // Fix up our attendees for invitations using some good defaults
+                let recipients = [];
+                let itemAtt = requestItem.getAttendees({});
                 if (!isMinorUpdate) {
-                    attendee = attendee.clone();
-                    attendee.role = "REQ-PARTICIPANT";
-                    attendee.participationStatus = "NEEDS-ACTION";
-                    attendee.rsvp = "TRUE";
-                    requestItem.addAttendee(attendee);
+                    requestItem.removeAllAttendees();
                 }
-                recipients.push(attendee);
-            }
+                for each (let attendee in itemAtt) {
+                    if (!isMinorUpdate) {
+                        attendee = attendee.clone();
+                        attendee.role = "REQ-PARTICIPANT";
+                        attendee.participationStatus = "NEEDS-ACTION";
+                        attendee.rsvp = "TRUE";
+                        requestItem.addAttendee(attendee);
+                    }
+                    recipients.push(attendee);
+                }
 
-            if (recipients.length > 0) {
-                sendMessage(requestItem, "REQUEST", recipients, autoResponse);
+                if (recipients.length > 0) {
+                    sendMessage(requestItem, "REQUEST", recipients, autoResponse);
+                }
+
             }
         }
 
         // Cancel the event for all canceled attendees
         if (canceledAttendees.length > 0) {
             let cancelItem = aOriginalItem.clone();
             cancelItem.removeAllAttendees();
             for each (let att in canceledAttendees) {
@@ -383,30 +387,63 @@ function setReceivedInfo(item, itipItemI
     let dtstamp = cal.itip.getStamp(itipItemItem);
     if (dtstamp) {
         item.setProperty(cal.calInstanceOf(item, Components.interfaces.calIAttendee) ? "RECEIVED-DTSTAMP"
                                                                                      : "X-MOZ-RECEIVED-DTSTAMP",
                          dtstamp.getInTimezone(cal.UTC()).icalString);
     }
 }
 
+/**
+ * Strips user specific data, e.g. categories and alarm settings and returns the stripped item.
+ */
+function stripUserData(item_) {
+    let item = item_.clone();
+    let stamp = item.stampTime;
+    let lastModified = item.lastModifiedTime;
+    item.alarmOffset = null;
+    item.alarmLastAck = null;
+    item.setCategories(0, []);
+    item.deleteProperty("RECEIVED-SEQUENCE");
+    item.deleteProperty("RECEIVED-DTSTAMP");
+    let propEnum = item.propertyEnumerator;
+    while (propEnum.hasMoreElements()) {
+        let prop = propEnum.getNext().QueryInterface(Components.interfaces.nsIProperty);
+        let pname = prop.name;
+        if (pname.substr(0, "X-MOZ-".length) == "X-MOZ-") {
+            item.deleteProperty(prop.name);
+        }
+    }
+    item.getAttendees({}).forEach(
+        function(att) {
+            att.deleteProperty("RECEIVED-SEQUENCE");
+            att.deleteProperty("RECEIVED-DTSTAMP");
+        });
+    item.setProperty("DTSTAMP", stamp);
+    item.setProperty("LAST-MODIFIED", lastModified); // need to be last to undirty the item
+    return item;
+}
+
 /** local to this module file
  * Takes over relevant item information from iTIP item and sets received info.
  *
  * @param item   the stored calendar item to update
  * @param itipItemItem the received item
  */
 function updateItem(item, itipItemItem) {
     let newItem = item.clone();
     newItem.icalComponent = itipItemItem.icalComponent;
     setReceivedInfo(newItem, itipItemItem);
+    // preserve user settings:
     newItem.generation = item.generation;
     newItem.alarmOffset = item.alarmOffset;
     newItem.alarmRelated = item.alarmRelated;
     newItem.alarmLastAck = item.alarmLastAck;
+    let cats = item.getCategories({});
+    newItem.setCategories(cats.length, cats);
     return newItem;
 }
 
 /** local to this module file
  * Creates an organizer calIAttendee object based on the calendar's configured organizer id.
  *
  * @return calIAttendee object
  */