]> git.cworth.org Git - sup/commitdiff
bugfix: label counts not set correctly on new messages
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 19:12:25 +0000 (15:12 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 19:12:25 +0000 (15:12 -0400)
New labels were being deleted when label-list-mode was brought
up before they were sync'ed to disk. This fixes that, although
this whole thing should be changed. (See comments.)

lib/sup/label.rb
lib/sup/modes/label-list-mode.rb

index 8902dda5757584c4c9dee553ae4146e415544545..47d632baafaa58e2dfa10111172b64e08b9f9f55 100644 (file)
@@ -19,12 +19,15 @@ class LabelManager
         []
       end
     @labels = {}
+    @new_labels = {}
     @modified = false
     labels.each { |t| @labels[t] = true }
 
     self.class.i_am_the_instance self
   end
 
+  def new_label? l; @new_labels.include?(l) end
+
   ## all labels user-defined and system, ordered
   ## nicely and converted to pretty strings. use #label_for to recover
   ## the original label.
@@ -63,12 +66,13 @@ class LabelManager
     t = t.intern unless t.is_a? Symbol
     unless @labels.member?(t) || RESERVED_LABELS.member?(t)
       @labels[t] = true
+      @new_labels[t] = true
       @modified = true
     end
   end
 
   def delete t
-    if @labels.delete t
+    if @labels.delete(t)
       @modified = true
     end
   end
@@ -76,6 +80,7 @@ class LabelManager
   def save
     return unless @modified
     File.open(@fn, "w") { |f| f.puts @labels.keys.sort_by { |l| l.to_s } }
+    @new_labels = {}
   end
 end
 
index a35d110df8d0607589b9c412682818674c181c9c..53287c1156611dc835ab87c571a27b52d7c092b6 100644 (file)
@@ -65,7 +65,14 @@ protected
 
     @labels = []
     counts.map do |label, string, total, unread|
-      if total == 0 && !LabelManager::RESERVED_LABELS.include?(label)
+      ## if we've done a search and there are no messages for this label, we can delete it from the
+      ## list. BUT if it's a brand-new label, the user may not have sync'ed it to the index yet, so
+      ## don't delete it in this case.
+      ##
+      ## this is all a hack. what should happen is:
+      ##   TODO make the labelmanager responsible for label counts
+      ## and then it can listen to labeled and unlabeled events, etc.
+      if total == 0 && !LabelManager::RESERVED_LABELS.include?(label) && !LabelManager.new_label?(label)
         Redwood::log "no hits for label #{label}, deleting"
         LabelManager.delete label
         next