commit 19c702767bdb0e4ab74da3bb49604135fbc19cf4
parent 7eb45c6e6d3fc05262900077c21f5245dd61bbcb
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Mon, 18 May 2009 15:12:25 -0400
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.)
Diffstat:
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git 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
@@ -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