sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 8f527cafa779dddff1c82ece0c44569598604040
parent 7ab4ac77fed2a214c85e4f0d5981ea3bd397b7f4
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Sun,  3 Jun 2007 22:47:12 +0000

thread-index-mode and subclass refactoring for conciseness and better thread auto-loading (no more arbitrary 1 second delay!)

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

Diffstat:
M lib/sup/modes/inbox-mode.rb | 18 ++++++------------
M lib/sup/modes/label-search-results-mode.rb | 17 +----------------
M lib/sup/modes/person-search-results-mode.rb | 17 +----------------
M lib/sup/modes/search-results-mode.rb | 23 ++++++-----------------
M lib/sup/modes/thread-index-mode.rb | 32 ++++++++++++++++++++++++++------
5 files changed, 40 insertions(+), 67 deletions(-)
diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb
@@ -9,10 +9,15 @@ class InboxMode < ThreadIndexMode
   end
 
   def initialize
-    super [:inbox], [:inbox]
+    super [:inbox, :sent], { :label => :inbox }
+    raise "can't have more than one!" if defined? @@instance
     @@instance = self
   end
 
+  def is_relevant? m; m.has_label? :inbox; end
+
+  ## label-list-mode wants to be able to raise us if the user selects
+  ## the "inbox" label, so we need to keep our singletonness around
   def self.instance; @@instance; end
   def killable?; false; end
 
@@ -47,17 +52,6 @@ class InboxMode < ThreadIndexMode
   def status
     super + "    #{Index.size} messages in index"
   end
-
-  def is_relevant? m; m.has_label? :inbox; end
-
-  def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
-    load_n_threads_background n, :label => :inbox,
-                                 :when_done => (lambda do |num|
-      opts[:when_done].call(num) if opts[:when_done]
-      BufferManager.flash "Added #{num} threads."
-    end)
-  end
 end
 
 end
diff --git a/lib/sup/modes/label-search-results-mode.rb b/lib/sup/modes/label-search-results-mode.rb
@@ -3,25 +3,10 @@ module Redwood
 class LabelSearchResultsMode < ThreadIndexMode
   def initialize labels
     @labels = labels
-    super
+    super [], { :labels => @labels }
   end
 
   def is_relevant? m; @labels.all? { |l| m.has_label? l }; end
-
-  def load_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(num) if opts[:when_done]
-      if num > 0
-        BufferManager.flash "Found #{num} threads"
-      else
-        BufferManager.flash "No matches"
-      end
-    end)
-  end
 end
 
 end
diff --git a/lib/sup/modes/person-search-results-mode.rb b/lib/sup/modes/person-search-results-mode.rb
@@ -3,25 +3,10 @@ module Redwood
 class PersonSearchResultsMode < ThreadIndexMode
   def initialize people
     @people = people
-    super
+    super [], { :participants => @people }
   end
 
   def is_relevant? m; @people.any? { |p| m.from == p }; end
-
-  def load_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(num) if opts[:when_done]
-      if num > 0
-        BufferManager.flash "Found #{num} threads"
-      else
-        BufferManager.flash "No matches"
-      end
-    end)
-  end
 end
 
 end
diff --git a/lib/sup/modes/search-results-mode.rb b/lib/sup/modes/search-results-mode.rb
@@ -3,26 +3,15 @@ module Redwood
 class SearchResultsMode < ThreadIndexMode
   def initialize qobj
     @qobj = qobj
-    super
+    super [], { :qobj => @qobj, :load_killed => true, :load_spam => false }
   end
 
-  ## TODO: think about this
-  def is_relevant? m; super; end
+  ## a proper is_relevant? method requires some way of asking ferret
+  ## if an in-memory object satisfies a query. i'm not sure how to do
+  ## that yet. in the worst case i can make an in-memory index, add
+  ## the message, and search against it to see if i have > 0 results,
+  ## but that seems pretty insane.
 
-  def load_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(num) if opts[:when_done]
-      if num > 0
-        BufferManager.flash "Found #{num} threads"
-      else
-        BufferManager.flash "No matches"
-      end
-    end)
-  end
 end
 
 end
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -1,7 +1,8 @@
-require 'thread'
 module Redwood
 
-## subclasses should implement load_threads
+## subclasses should implement:
+## - is_relevant?
+
 class ThreadIndexMode < LineCursorMode
   DATE_WIDTH = Time::TO_NICE_S_MAX_LEN
   FROM_WIDTH = 15
@@ -26,10 +27,10 @@ class ThreadIndexMode < LineCursorMode
     k.add :apply_to_tagged, "Apply next command to all tagged threads", ';'
   end
 
-  def initialize required_labels=[], hidden_labels=[]
+  def initialize hidden_labels=[], load_thread_opts={}
     super()
     @load_thread = nil
-    @required_labels = required_labels
+    @load_thread_opts = load_thread_opts
     @hidden_labels = hidden_labels + LabelManager::HIDDEN_LABELS
     @date_width = DATE_WIDTH
     @from_width = FROM_WIDTH
@@ -45,9 +46,9 @@ class ThreadIndexMode < LineCursorMode
 
     to_load_more do |size|
       next if @last_load_more_size == 0
-      load_threads :num => size,
+      load_threads :num => 1, :background => false
+      load_threads :num => (size - 1),
                    :when_done => lambda { |num| @last_load_more_size = num }
-      sleep 1.0 # give 'em a chance to load
     end
   end
 
@@ -374,6 +375,25 @@ class ThreadIndexMode < LineCursorMode
     end
   end
 
+  def load_threads opts={}
+    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+
+    myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
+      opts[:when_done].call(num) if opts[:when_done]
+      if num > 0
+        BufferManager.flash "Found #{num} threads"
+      else
+        BufferManager.flash "No matches"
+      end
+    end)})
+
+    if opts[:background]
+      load_n_threads_background n, myopts
+    else
+      load_n_threads n, myopts
+    end
+  end
+
 protected
 
   def cursor_thread; @threads[curpos]; end