[california] Fix regression preventing recurring events from gen'ing instances



commit 28058d09ad469d01acb8364b123f735d8ec4c7b8
Author: Jim Nelson <jim yorba org>
Date:   Thu Jun 26 16:41:42 2014 -0700

    Fix regression preventing recurring events from gen'ing instances
    
    Recurring events were not generating all instances.  This was fixed
    in commit ad99022.  However, this bug was reintroduced when the switch
    to async I/O was introduced (commit c5d3b5c).  This patch re-fixes the
    problem.

 .../backing-calendar-source-subscription.vala      |   23 ++++++++
 .../backing-eds-calendar-source-subscription.vala  |   58 +++++++-------------
 2 files changed, 44 insertions(+), 37 deletions(-)
---
diff --git a/src/backing/backing-calendar-source-subscription.vala 
b/src/backing/backing-calendar-source-subscription.vala
index 7ab5236..71216fd 100644
--- a/src/backing/backing-calendar-source-subscription.vala
+++ b/src/backing/backing-calendar-source-subscription.vala
@@ -277,6 +277,29 @@ public abstract class CalendarSourceSubscription : BaseObject {
         return instances.contains(uid) ? instances.get(uid) : null;
     }
     
+    /**
+     * Returns the seen { link Component.Instance} matching the supplied (possibly partially
+     * filled-out) Instance.
+     *
+     * This is for duplicate detection, especially if the { link Backing} is receiving raw iCal
+     * source and needs to verify if it's been parsed and introduced into the system.
+     *
+     * A blank Instance with partial fields filled out can be supplied.
+     */
+    public Component.Instance? has_instance(Component.Instance instance) {
+        Gee.Collection<Component.Instance>? seen_instances = for_uid(instance.uid);
+        if (seen_instances == null || seen_instances.size == 0)
+            return null;
+        
+        // for every instance matching its UID, look for the original
+        foreach (Component.Instance seen_instance in seen_instances) {
+            if (seen_instance.equal_to(instance))
+                return seen_instance;
+        }
+        
+        return null;
+    }
+    
     public override string to_string() {
         return "%s::%s".printf(calendar.to_string(), window.to_string());
     }
diff --git a/src/backing/eds/backing-eds-calendar-source-subscription.vala 
b/src/backing/eds/backing-eds-calendar-source-subscription.vala
index f38932d..0da9af6 100644
--- a/src/backing/eds/backing-eds-calendar-source-subscription.vala
+++ b/src/backing/eds/backing-eds-calendar-source-subscription.vala
@@ -126,38 +126,31 @@ internal class EdsCalendarSourceSubscription : CalendarSourceSubscription {
         time_t instance_end) {
         unowned iCal.icalcomponent ical_component = eds_component.get_icalcomponent();
         
-        // if no UID, go no further
-        string? uid = ical_component.get_uid();
-        if (String.is_empty(uid))
+        // convert the added component into a new Event
+        Component.Event? added_event;
+        try {
+            added_event = Component.Instance.convert(calendar, ical_component) as Component.Event;
+            if (added_event == null)
+                return true;
+        } catch (Error err) {
+            debug("Unable to process added event: %s", err.message);
+            
             return true;
+        }
         
-        // if UID has been seen, go no further
-        if (has_uid(new Component.UID(uid)))
+        // see if this was seen before
+        Component.Event? seen_event = has_instance(added_event) as Component.Event;
+        if (seen_event != null)
             return true;
         
-        try {
-            Component.Event? event = Component.Instance.convert(calendar, ical_component)
-                as Component.Event;
-            if (event != null)
-                notify_instance_added(event);
-        } catch (Error err) {
-            debug("Unable to generate added event for %s: %s", to_string(), err.message);
-        }
+        // nope, it's a new one
+        notify_instance_added(added_event);
         
         return true;
     }
     
     private void on_objects_modified(SList<weak iCal.icalcomponent> objects) {
         foreach (weak iCal.icalcomponent ical_component in objects) {
-            // only update known objects
-            string? uid = ical_component.get_uid();
-            if (String.is_empty(uid))
-                continue;
-            
-            Gee.Collection<Component.Instance>? instances = for_uid(new Component.UID(uid));
-            if (instances == null || instances.size == 0)
-                continue;
-            
             // convert the modified event source into an orphaned event (for comparison purposes)
             Component.Event modified_event;
             try {
@@ -168,27 +161,18 @@ internal class EdsCalendarSourceSubscription : CalendarSourceSubscription {
                 continue;
             }
             
-            // for every instance matching its UID, look for the original
-            Component.Event? event = null;
-            foreach (Component.Instance instance in instances) {
-                Component.Event? stored_event = instance as Component.Event;
-                if (stored_event != null && stored_event.equal_to(modified_event)) {
-                    event = stored_event;
-                    
-                    break;
-                }
-            }
-            
-            if (event == null)
+            // find original event instance for this one
+            Component.Event? seen_event = has_instance(modified_event) as Component.Event;
+            if (seen_event == null)
                 continue;
             
             try {
-                event.full_update(ical_component, null);
+                seen_event.full_update(ical_component, null);
             } catch (Error err) {
-                debug("Unable to update event %s: %s", event.to_string(), err.message);
+                debug("Unable to update event %s: %s", seen_event.to_string(), err.message);
             }
             
-            notify_instance_altered(event);
+            notify_instance_altered(seen_event);
         }
     }
     


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]