[gnome-contacts/nielsdg/fix-ignored-individuals: 2/2] store: Fix ignoring newly added individuals




commit 2e1f75708e04896464a83869b3fcdd5969705316
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Thu Sep 8 07:50:08 2022 +0200

    store: Fix ignoring newly added individuals
    
    Apparently, Vala isn't smart enough to be able to deal with a `foreach`
    statement and remove elements at the same time, leading to some
    unexpected results.
    
    This commit fixes it by just using a classic index-based `for`-loop.

 src/contacts-store.vala | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 6a392404..7a70cad6 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -207,9 +207,11 @@ public class Contacts.Store : GLib.Object {
     }
 
     // Add new individuals
-    foreach (unowned var indiv in to_add) {
+    for (uint i = 0; i < to_add.length; i++) {
+      unowned var indiv = to_add[i];
       if (indiv.personas.size == 0 || Utils.is_ignorable (indiv)) {
-        to_add.remove_fast (indiv);
+        to_add.remove_index_fast (i);
+        i--;
       } else {
         // We want to make sure that changes in the Individual triggers changes
         // in the list model if it affects sorting and/or filtering. Atm, the


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