Subject: [sup-talk] [PATCH] Add command for polling unusual sources

From: [email-masked] (Bo Borgerson)
Date: Sun, 13 Sep 2009 10:38:35 -0400

bin/sup: Add new global key binding, '{', to poll unusual sources
(requires confirmation).  This allows update of unusual sources
without having to leave sup to run a sync.

lib/sup/poll.rb: Add new method, poll_unusual.  Both the pre-existing
poll method and the new poll_unusual method are now wrappers around
new poll_with_sources method that contains the bulk of functionality
previously in poll.

lib/sup/source.rb: Add new accessor for unusual_sources
---
 bin/sup           |    5 +++++
 lib/sup/poll.rb   |   23 +++++++++++++++++++----
 lib/sup/source.rb |    1 +
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/bin/sup b/bin/sup
index 76a0438..996c99e 100755
--- a/bin/sup
+++ b/bin/sup
@@ -75,6 +75,7 @@ global_keymap = Keymap.new do |k|
   k.add :search_unread, "Show all unread messages", 'U'
   k.add :list_labels, "List labels", 'L'
   k.add :poll, "Poll for new messages", 'P'
+  k.add :poll_unusual, "Poll for new messages from unusual sources", '{'
   k.add :compose, "Compose new message", 'm', 'c'
   k.add :nothing, "Do nothing", :ctrl_g
   k.add :recall_draft, "Edit most recent draft message", 'R'
@@ -282,6 +283,10 @@ begin
       ComposeMode.spawn_nicely
     when :poll
       reporting_thread("user-invoked poll") { PollManager.poll }
+    when :poll_unusual
+      if BufferManager.ask_yes_or_no "Really poll unusual sources?"
+        reporting_thread("user-invoked unusual poll") { PollManager.poll_unusual }
+      end
     when :recall_draft
       case Index.num_results_for :label => :draft
       when 0
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
index b59237f..ec51dec 100644
--- a/lib/sup/poll.rb
+++ b/lib/sup/poll.rb
@@ -35,12 +35,11 @@ EOS
     @thread = nil
     @last_poll = nil
     @polling = false
+    @poll_sources = nil
     @mode = nil
   end
 
-  def poll
-    return if @polling
-    @polling = true
+  def poll_with_sources
     @mode ||= PollMode.new
     HookManager.run "before-poll"
 
@@ -54,6 +53,22 @@ EOS
 
     HookManager.run "after-poll", :num => num, :num_inbox => numi, :from_and_subj => from_and_subj, :from_and_subj_inbox => from_and_subj_inbox, :num_inbox_total_unread => lambda { Index.num_results_for :labels => [:inbox, :unread] }
 
+  end
+
+  def poll
+    return if @polling
+    @polling = true
+    @poll_sources = SourceManager.usual_sources
+    num, numi = poll_with_sources
+    @polling = false
+    [num, numi]
+  end
+
+  def poll_unusual
+    return if @polling
+    @polling = true
+    @poll_sources = SourceManager.unusual_sources
+    num, numi = poll_with_sources
     @polling = false
     [num, numi]
   end
@@ -78,7 +93,7 @@ EOS
     from_and_subj_inbox = []
 
     @mutex.synchronize do
-      SourceManager.usual_sources.each do |source|
+      @poll_sources.each do |source|
 #        yield "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})"
         begin
           yield "Loading from #{source}... " unless source.done? || (source.respond_to?(:has_errors?) && source.has_errors?)
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
index 78386ff..6fe7bfb 100644
--- a/lib/sup/source.rb
+++ b/lib/sup/source.rb
@@ -207,6 +207,7 @@ class SourceManager
 
   def source_for uri; sources.find { |s| s.is_source_for? uri }; end
   def usual_sources; sources.find_all { |s| s.usual? }; end
+  def unusual_sources; sources.find_all { |s| !s.usual? }; end
 
   def load_sources fn=Redwood::SOURCE_FN
     source_array = (Redwood::load_yaml_obj(fn) || []).map { |o| Recoverable.new o }
-- 
1.6.0.4

---

From: [email-masked] (William Morgan)
Date: Thu, 01 Oct 2009 09:54:48 -0700

> without having to leave sup to run a sync.

Branch poll-unusual, merged into next. Thanks!
-- 
William <wmorgan-sup at masanjin.net>