]> git.cworth.org Git - sup/blobdiff - lib/sup/poll.rb
Merge branch 'cancel-search' into next
[sup] / lib / sup / poll.rb
index 2faadfe87634d6f1d31bf3ebd0e870d2fa19bb06..2dd915011c26c8310a0290f5499c0f18b80e9d94 100644 (file)
@@ -19,12 +19,13 @@ EOS
   HookManager.register "after-poll", <<EOS
 Executes immediately after a poll for new messages completes.
 Variables:
-                  num: the total number of new messages
-            num_inbox: the number of new messages appearing in the inbox (i.e.
-                       not auto-archived).
-        from_and_subj: an array of (from email address, subject) pairs
-  from_and_subj_inbox: an array of (from email address, subject) pairs for
-                       only those messages appearing in the inbox
+                   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_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
+                        only those messages appearing in the inbox
 EOS
 
   DELAY = 300
@@ -39,7 +40,8 @@ EOS
   end
 
   def buffer
-    @buffer ||= BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) { PollMode.new }
+    b, new = BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) { PollMode.new }
+    b
   end
 
   def poll
@@ -55,14 +57,14 @@ EOS
       BufferManager.flash "No new messages." 
     end
 
-    HookManager.run "after-poll", :num => num, :num_inbox => numi, :from_and_subj => from_and_subj, :from_and_subj_inbox => from_and_subj_inbox
+    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] }
 
     @polling = false
     [num, numi]
   end
 
   def start
-    @thread = Redwood::reporting_thread do
+    @thread = Redwood::reporting_thread("periodic poll") do
       while true
         sleep DELAY / 2
         poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
@@ -156,7 +158,7 @@ EOS
           HookManager.run "before-add-message", :message => m
           m = yield(m, offset, entry) or next
           Index.sync_message m, docid, entry
-          UpdateManager.relay self, :add, m unless entry
+          UpdateManager.relay self, :added, m unless entry
         rescue MessageFormatError => e
           Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}"
         end