core: Ensure we always notify of new Individuals
authorPhilip Withnall <philip@tecnocode.co.uk>
Tue, 6 Sep 2011 20:57:42 +0000 (21:57 +0100)
committerRaul Gutierrez Segales <rgs@collabora.co.uk>
Wed, 7 Sep 2011 21:53:36 +0000 (22:53 +0100)
In the following situation, it was possible for
IndividualAggregator.individuals_changed_detailed to not emit a notification
that an individual was added:

If two personas were added by a given store in the same emission of
PersonaStore.personas_changed, the IA would create an Individual, i1, from
the first and add a mapping (null → i1) to the change set. It would then
process the second, destroying the first individual and creating a new
Individual, i2, (correctly) containing both personas. In doing so, it would
remove the mapping (null → i1) from the change set, but would incorrectly
not add a mapping (null → i2) in its place.

This situation can be extended to others where a single new Individual is
formed from multiple new personas coming from a single emission of
PersonaStore.personas_changed.

Closes: bgo#657282 (again)

folks/individual-aggregator.vala

index 38c4280..bb8cfd9 100644 (file)
@@ -834,6 +834,8 @@ public class Folks.IndividualAggregator : Object
               this._add_persona_to_link_map (p, final_individual);
             }
 
+          uint num_mappings_added = 0;
+
           foreach (var i in candidate_inds)
             {
               /* Transitively update the individuals_changes. We have to do this
@@ -860,6 +862,7 @@ public class Folks.IndividualAggregator : Object
                   if (k != null)
                     {
                       individuals_changes.set (k, final_individual);
+                      num_mappings_added++;
                     }
                 }
 
@@ -870,12 +873,14 @@ public class Folks.IndividualAggregator : Object
               if (transitive_updates.size == 0)
                 {
                   individuals_changes.set (i, final_individual);
+                  num_mappings_added++;
                 }
             }
 
-          /* If there were no candidate individuals, mark the final_individual
-           * as added. */
-          if (candidate_inds.size == 0)
+          /* If there were no candidate individuals or they were all freshly
+           * added (i.e. mapped from null → candidate_individual), mark the
+           * final_individual as added. */
+          if (num_mappings_added == 0)
             {
               individuals_changes.set (null, final_individual);
             }