]> git.notmuchmail.org Git - sup/commitdiff
sadly, that thread invariant cannot be maintained without creating bugs.
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 31 Dec 2007 02:26:24 +0000 (18:26 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 31 Dec 2007 02:26:24 +0000 (18:26 -0800)
lib/sup/thread.rb

index d41cb515c1328d51cf3aa8393f7d988ec813ff2f..ab15493654acddff79be066082d44445ff5a0781 100644 (file)
@@ -256,10 +256,6 @@ end
 ## one thread, even if they don't reference each other. This is
 ## helpful for crappy MUAs that don't set In-reply-to: or References:
 ## headers, but means that messages may be threaded unnecessarily.
-##
-## The following invariants should be maintained: every Thread
-## should have at least one Container tree, and every Container tree
-## should have at least one Message.
 class ThreadSet
   attr_reader :num_messages
   bool_reader :thread_by_subj
@@ -279,8 +275,8 @@ class ThreadSet
   def thread_for m; thread_for_id m.id end
   def contains? m; contains_id? m.id end
 
-  def threads; @threads.values end
-  def size; @threads.size end
+  def threads; prune_empty_threads.values end
+  def size; prune_empty_threads.size end
 
   ## unused
   def dump f
@@ -312,14 +308,14 @@ class ThreadSet
     thread = c.root.thread # find containing thread
     if thread
       thread.prune_dangling_container_trees!
-      if thread.empty? # kill the thread
-        @threads.delete_if { |key, thread| thread.empty? }
-        c.root.thread = nil
-      end
+      c.root.thread = nil
     end
   end
   private :remove_container
 
+  def prune_empty_threads; @threads.delete_if { |k, t| t.empty? } end
+  private :prune_empty_threads
+
   ## remove a single message id. not used anywhere, afaik.
   def remove_id mid
     return unless(c = @messages[mid])