[blam] Item: Really fix value reset



commit c7ac9cf1c5a5a44e3d225c8a0cf418adc421ea96
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Sat Mar 26 12:06:31 2011 +0100

    Item: Really fix value reset
    
    Add an `init' flag, set after item initialisation, to indicate when we
    can skip loading the extensions.
    
    Every time we store the item DB, the extensions are written, so it
    doesn't help to clear them just once.
    
    Signed-off-by: Carlos Martín Nieto <carlos cmartin tk>

 src/Item.cs |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/src/Item.cs b/src/Item.cs
index 35be5f8..dc8ebf9 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -18,6 +18,7 @@ namespace Imendio.Blam {
 
         private int ref_cnt = 0;
         private Object obj = new Object();
+        private bool init = false;
         public SyndicationContent exposed_text = null;
 
         public delegate void UpdateHandler(Item item);
@@ -89,10 +90,19 @@ namespace Imendio.Blam {
             }
 
             foreach(SyndicationElementExtension ext in this.ElementExtensions){
+                if(ext.OuterName == "encoded"){
+                    item.Content = new TextSyndicationContent(ext.GetObject<string>());
+                    exposed_text = item.Content;
+                }
+
+                if(init){
+                    return;
+                }
+
                 switch(ext.OuterNamespace){
-                /* Read our Item properties */
-                case "blam":
-                    switch(ext.OuterName){
+                   /* Read our Item properties */
+                    case "blam":
+                        switch(ext.OuterName){
                     case "unread":
                         Unread = ext.GetObject<bool>();
                         break;
@@ -111,28 +121,22 @@ namespace Imendio.Blam {
                     }
                     break;
                 }
-
-                if(ext.OuterName == "encoded"){ /* Only executed on a new entry */
-                    item.Content = new TextSyndicationContent(ext.GetObject<string>());
-                    exposed_text = item.Content;
-                 }
             }
         }
 
         public Item(SyndicationItem item) : base(item)
         {
-            FillItem(item);
-            /*
-             * If we don't clear the extensions, the values will be
-             * reset on each update (Unread and ref_cnt being the most
-             * worrysome.
-             */
-            ElementExtensions.Clear();
+            lock(obj){
+                FillItem(item);
+                init = true;
+            }
         }
 
         public bool Update(SyndicationItem item)
         {
-            FillItem(item);
+            lock(obj){
+                FillItem(item);
+            }
             return true;
         }
 



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