From ee34231b2932ae29c7b9c93f1198f33c9fab8372 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Fri, 9 Feb 2007 07:40:42 +0000 Subject: [PATCH] fixed broken draft autoloading on first draft git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@310 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- doc/TODO | 1 + lib/sup/draft.rb | 15 ++++++++++++--- lib/sup/modes/thread-index-mode.rb | 3 ++- lib/sup/poll.rb | 1 + lib/sup/source.rb | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/TODO b/doc/TODO index 3233779..1fb1355 100644 --- a/doc/TODO +++ b/doc/TODO @@ -9,6 +9,7 @@ bugfix: changing IMAP ids de-archived messages should be auto-added to inbox maildir undo +remove stupid percent_done source methods future ------ diff --git a/lib/sup/draft.rb b/lib/sup/draft.rb index 49ddf3f..ce292be 100644 --- a/lib/sup/draft.rb +++ b/lib/sup/draft.rb @@ -55,9 +55,9 @@ class DraftLoader < Source def uri; DraftManager.source_name; end def each - ids = Dir.entries(@dir).select { |x| x =~ /^\d+$/ }.map { |x| x.to_i }.sort + ids = get_ids ids.each do |id| - if id > cur_offset + if id >= cur_offset self.cur_offset = id yield [id, [:draft, :inbox]] end @@ -107,7 +107,16 @@ class DraftLoader < Source end def start_offset; 0; end - def end_offset; Dir.new(@dir).entries.sort.last.to_i; end + def end_offset + ids = get_ids + ids.empty? ? 0 : (ids.last + 1) + end + +private + + def get_ids + Dir.entries(@dir).select { |x| x =~ /^\d+$/ }.map { |x| x.to_i }.sort + end end Redwood::register_yaml(DraftLoader, %w(cur_offset)) diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 70bbffd..9cceaa6 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -57,6 +57,7 @@ class ThreadIndexMode < LineCursorMode def select t=nil t ||= @threads[curpos] + ## this isn't working entirely. TODO:figure out why t = t.clone # required so that messages added later on don't completely # screw everything up @@ -327,7 +328,7 @@ class ThreadIndexMode < LineCursorMode def load_n_threads n=LOAD_MORE_THREAD_NUM, opts={} @mbid = BufferManager.say "Searching for threads..." orig_size = @ts.size - last_update = Time.now + last_update = Time.now - 9999 # oh yeah @ts.load_n_threads(@ts.size + n, opts) do |i| BufferManager.say "Loaded #{i} threads...", @mbid if (Time.now - last_update) >= 0.25 diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb index 009f26b..cbad96c 100644 --- a/lib/sup/poll.rb +++ b/lib/sup/poll.rb @@ -43,6 +43,7 @@ class PollManager @mutex.synchronize do found = {} Index.usual_sources.each do |source| +# yield "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})" yield "Loading from #{source}... " unless source.done? || source.broken? num = 0 numi = 0 diff --git a/lib/sup/source.rb b/lib/sup/source.rb index 9571d6a..8aa3537 100644 --- a/lib/sup/source.rb +++ b/lib/sup/source.rb @@ -25,7 +25,7 @@ class Source ## To write a new source, subclass this class, and implement: ## ## - start_offset - ## - end_offset + ## - end_offset (exclusive!) ## - pct_done (percent of the way cur_offset is to end_offset) ## - load_header offset ## - load_message offset -- 2.45.2