[]
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.
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
def save
return unless @modified
File.open(@fn, "w") { |f| f.puts @labels.keys.sort_by { |l| l.to_s } }
+ @new_labels = {}
end
end
@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