From: William Morgan Date: Mon, 18 May 2009 19:12:25 +0000 (-0400) Subject: bugfix: label counts not set correctly on new messages X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=19c702767bdb0e4ab74da3bb49604135fbc19cf4;p=sup bugfix: label counts not set correctly on new messages 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.) --- diff --git a/lib/sup/label.rb b/lib/sup/label.rb index 8902dda..47d632b 100644 --- a/lib/sup/label.rb +++ b/lib/sup/label.rb @@ -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 diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb index a35d110..53287c1 100644 --- a/lib/sup/modes/label-list-mode.rb +++ b/lib/sup/modes/label-list-mode.rb @@ -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