]> git.cworth.org Git - sup/blobdiff - lib/sup/thread.rb
make >From thing work correctly
[sup] / lib / sup / thread.rb
index 020cf7256b4d7ebec4e2723a476f3d7961bd6181..b154ac02925fdf89e67b563b4e2636b1ad1d134d 100644 (file)
@@ -54,7 +54,7 @@ class Thread
 
   ## yields each message, its depth, and its parent. the message yield
   ## parameter can be a Message object, or :fake_root, or nil (no
-  ## message found but the presence of one induced from other
+  ## message found but the presence of one deduced from other
   ## messages).
   def each fake_root=false
     adj = 0
@@ -85,7 +85,10 @@ class Thread
   def first; each { |m, *o| return m if m }; nil; end
   def dirty?; any? { |m, *o| m && m.dirty? }; end
   def date; map { |m, *o| m.date if m }.compact.max; end
-  def snippet; argfind { |m, *o| m && m.snippet }; end
+  def snippet
+    last_m, last_stuff = select { |m, *o| m && m.snippet && !m.snippet.empty? }.sort_by { |m, *o| m.date }.last
+    last_m ? last_m.snippet : ""
+  end
   def authors; map { |m, *o| m.from if m }.compact.uniq; end
 
   def apply_label t; each { |m, *o| m && m.add_label(t) }; end
@@ -303,18 +306,19 @@ class ThreadSet
       next if contains_id? mid
 
       m = builder.call
-      add_message m
-      load_thread_for_message m, :load_killed => opts[:load_killed]
+      load_thread_for_message m, :load_killed => opts[:load_killed], :load_deleted => opts[:load_deleted], :load_spam => opts[:load_spam]
       yield size if block_given?
     end
   end
 
   ## loads in all messages needed to thread m
+  ## may do nothing if m's thread is killed
   def load_thread_for_message m, opts={}
-    @index.each_message_in_thread_for m, opts.merge({:limit => 100}) do |mid, builder|
+    good = @index.each_message_in_thread_for m, opts do |mid, builder|
       next if contains_id? mid
       add_message builder.call
     end
+    add_message m if good
   end
 
   ## merges in a pre-loaded thread