lib/sup/poll.rb in sup-0.10.2 vs lib/sup/poll.rb in sup-0.11
- old
+ new
@@ -35,20 +35,27 @@
@thread = nil
@last_poll = nil
@polling = false
@poll_sources = nil
@mode = nil
+ @should_clear_running_totals = false
+ clear_running_totals # defines @running_totals
+ UpdateManager.register self
end
def poll_with_sources
@mode ||= PollMode.new
HookManager.run "before-poll"
BufferManager.flash "Polling for new messages..."
num, numi, from_and_subj, from_and_subj_inbox, loaded_labels = @mode.poll
- if num > 0
- BufferManager.flash "Loaded #{num.pluralize 'new message'}, #{numi} to inbox. Labels: #{loaded_labels.map{|l| l.to_s}.join(', ')}"
+ 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(', ')}"
else
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, :num_inbox_total_unread => lambda { Index.num_results_for :labels => [:inbox, :unread] }
@@ -181,8 +188,12 @@
## does the gui callback stuff, etc.
def add_new_message m
Index.add_message m
UpdateManager.relay self, :added, m
end
+
+ def handle_idle_update sender, idle_since; @should_clear_running_totals = false; end
+ def handle_unidle_update sender, idle_since; @should_clear_running_totals = true; clear_running_totals; end
+ def clear_running_totals; @running_totals = {:num => 0, :numi => 0, :loaded_labels => Set.new}; end
end
end