sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit d16bebcf34102579a935f890eb0a5adef372373d
parent aa099697ec4db9ef18141af402db425e68a1747d
Author: Whyme Lyu <callme5long@gmail.com>
Date:   Sun, 26 May 2013 20:36:26 +0800

Merge #70 'no-poll-flashing'

* Don't flash message when custom hooks before/after-poll are defined
* Pass num_total and num_inbox_total to after-pool hook
* Implement HookContext#flash

Diffstat:
M lib/sup/hook.rb | 8 ++++++++
M lib/sup/poll.rb | 29 ++++++++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
@@ -19,6 +19,14 @@ class HookManager
       end
     end
 
+    def flash s
+      if BufferManager.instantiated?
+        BufferManager.flash s
+      else
+        log s
+      end
+    end
+
     def log s
       info "hook[#@__name]: #{s}"
     end
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -22,6 +22,8 @@ Variables:
                    num: the total number of new messages added in this poll
              num_inbox: the number of new messages added in this poll which
                         appear in the inbox (i.e. were not auto-archived).
+             num_total: the total number of messages 
+       num_inbox_total: the total number of new messages in the inbox.
 num_inbox_total_unread: the total number of unread messages in the inbox
          from_and_subj: an array of (from email address, subject) pairs
    from_and_subj_inbox: an array of (from email address, subject) pairs for
@@ -43,22 +45,35 @@ EOS
 
   def poll_with_sources
     @mode ||= PollMode.new
-    HookManager.run "before-poll"
 
-    BufferManager.flash "Polling for new messages..."
+    if HookManager.enabled? "before-poll"
+      HookManager.run("before-poll")
+    else
+      BufferManager.flash "Polling for new messages..."
+    end
+
     num, numi, from_and_subj, from_and_subj_inbox, loaded_labels = @mode.poll
     clear_running_totals if @should_clear_running_totals
     @running_totals[:num] += num
     @running_totals[:numi] += numi
     @running_totals[:loaded_labels] += loaded_labels || []
-    if @running_totals[:num] > 0
-      BufferManager.flash "Loaded #{@running_totals[:num].pluralize 'new message'}, #{@running_totals[:numi]} to inbox. Labels: #{@running_totals[:loaded_labels].map{|l| l.to_s}.join(', ')}"
+   
+    
+    if HookManager.enabled? "after-poll"
+      hook_args = { :num => num, :num_inbox => numi,
+                    :num_total => @running_totals[:num], :num_inbox_total => @running_totals[: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] } }
+
+      HookManager.run("after-poll", hook_args) 
     else
-      BufferManager.flash "No new messages."
+      if @running_totals[:num] > 0
+        BufferManager.flash "Loaded #{@running_totals[:num].pluralize 'new message'}, #{@running_totals[:numi]} to inbox. Labels: #{@running_totals[:loaded_labels].map{|l| l.to_s}.join(', ')}"
+      else
+        BufferManager.flash "No new messages."
+      end
     end
 
-    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