sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit e63279d0b1c1efcfba9ff489fe0b116291e6c874
parent 105b1c00286e74d86e35e78de406b631510f1edf
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Wed,  3 Jan 2007 06:11:14 +0000

improved load_n_threads


git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@151 5c8cc53c-5e98-4d25-b20a-d8db53a31250

Diffstat:
M bin/sup | 7 +++----
M lib/sup/modes/contact-list-mode.rb | 2 +-
M lib/sup/modes/inbox-mode.rb | 10 ++++++----
M lib/sup/modes/label-list-mode.rb | 2 +-
M lib/sup/modes/label-search-results-mode.rb | 4 +++-
M lib/sup/modes/person-search-results-mode.rb | 4 +++-
M lib/sup/modes/search-results-mode.rb | 4 +++-
M lib/sup/modes/thread-index-mode.rb | 1 +
8 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -100,9 +100,8 @@ begin
   Logger.make_buf
 
   bm.draw_screen
-  imode.load_more_threads ibuf.content_height
+  imode.load_more_threads :num => ibuf.content_height, :when_done => lambda {   reporting_thread { sleep 1; PollManager.poll } }
 
-  reporting_thread { sleep 5; PollManager.poll }
   PollManager.start_thread
 
   until $exception
@@ -141,7 +140,7 @@ begin
             log "built query from #{text.inspect}: #{qobj}"
             mode = SearchResultsMode.new qobj
             bm.spawn "search: \"#{short_text}\"", mode
-            mode.load_more_threads mode.buffer.content_height
+            mode.load_more_threads :num => mode.buffer.content_height
           rescue Ferret::QueryParser::QueryParseException => e
             bm.flash "Couldn't parse query."
           end
@@ -168,7 +167,7 @@ begin
             b = BufferManager.spawn_unless_exists(:draft) do
               mode = LabelSearchResultsMode.new [:draft]
             end
-            b.mode.load_more_threads b.content_height
+            b.mode.load_more_threads :num => b.content_height
           end
         when :nothing
         when :redraw
diff --git a/lib/sup/modes/contact-list-mode.rb b/lib/sup/modes/contact-list-mode.rb
@@ -60,7 +60,7 @@ class ContactListMode < LineCursorMode
   def multi_search people
     mode = PersonSearchResultsMode.new people
     BufferManager.spawn "personal search results", mode
-    mode.load_more_threads mode.buffer.content_height
+    mode.load_more_threads :num => mode.buffer.content_height
   end
 
   def search
diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb
@@ -28,19 +28,21 @@ class InboxMode < ThreadIndexMode
 
   def is_relevant? m; m.has_label? :inbox; end
 
-  def load_more_threads n=ThreadIndexMode::LOAD_MORE_THREAD_NUM
+  def load_more_threads opts={}
+    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
     load_n_threads_background n, :label => :inbox,
                                  :load_killed => false,
                                  :load_spam => false,
-                                 :when_done => lambda { |num|
+                                 :when_done => (lambda do |num|
+      opts[:when_done].call if opts[:when_done]
       BufferManager.flash "Added #{num} threads."
-    }
+    end)
   end
 
   def reload
     drop_all_threads
     BufferManager.draw_screen
-    load_more_threads buffer.content_height
+    load_more_threads :num => buffer.content_height
   end
 end
 
diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb
@@ -81,7 +81,7 @@ protected
       b = BufferManager.spawn_unless_exists(label) do
         mode = LabelSearchResultsMode.new [label]
       end
-      b.mode.load_more_threads b.content_height
+      b.mode.load_more_threads :num => b.content_height
     end
   end
 end
diff --git a/lib/sup/modes/label-search-results-mode.rb b/lib/sup/modes/label-search-results-mode.rb
@@ -12,11 +12,13 @@ class LabelSearchResultsMode < ThreadIndexMode
 
   def is_relevant? m; @labels.all? { |l| m.has_label? l }; end
 
-  def load_more_threads n=ThreadIndexMode::LOAD_MORE_THREAD_NUM
+  def load_more_threads opts={}
+    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
     load_n_threads_background n, :labels => @labels,
                                  :load_killed => true,
                                  :load_spam => false,
                                  :when_done =>(lambda do |num|
+      opts[:when_done].call if opts[:when_done]
       if num > 0
         BufferManager.flash "Found #{num} threads"
       else
diff --git a/lib/sup/modes/person-search-results-mode.rb b/lib/sup/modes/person-search-results-mode.rb
@@ -12,11 +12,13 @@ class PersonSearchResultsMode < ThreadIndexMode
 
   def is_relevant? m; @people.any? { |p| m.from == p }; end
 
-  def load_more_threads n=ThreadIndexMode::LOAD_MORE_THREAD_NUM
+  def load_more_threads opts={}
+    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
     load_n_threads_background n, :participants => @people,
                                  :load_killed => true,
                                  :load_spam => false,
                                  :when_done =>(lambda do |num|
+      opts[:when_done].call if opts[:when_done]
       if num > 0
         BufferManager.flash "Found #{num} threads"
       else
diff --git a/lib/sup/modes/search-results-mode.rb b/lib/sup/modes/search-results-mode.rb
@@ -13,11 +13,13 @@ class SearchResultsMode < ThreadIndexMode
   ## TODO: think about this
   def is_relevant? m; super; end
 
-  def load_more_threads n=ThreadIndexMode::LOAD_MORE_THREAD_NUM
+  def load_more_threads opts={}
+    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
     load_n_threads_background n, :qobj => @qobj,
                                  :load_killed => true,
                                  :load_spam => false,
                                  :when_done =>(lambda do |num|
+      opts[:when_done].call if opts[:when_done]
       if num > 0
         BufferManager.flash "Found #{num} threads"
       else
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -72,6 +72,7 @@ class ThreadIndexMode < LineCursorMode
   def handle_add_update m
     if is_relevant?(m) || @ts.is_relevant?(m)
       @ts.load_thread_for_message m
+      @new_cache.delete @ts.thread_for(m) # force recalculation of newness
       update
     end
   end