lib/sup/thread.rb in sup-0.4 vs lib/sup/thread.rb in sup-0.5

- old
+ new

@@ -257,11 +257,11 @@ ## map from subject strings or (or root message ids) to thread objects @threads = SavingHash.new { Thread.new } @thread_by_subj = thread_by_subj end - def thread_for_id mid; (c = @messages[mid]) && c.root.thread end + def thread_for_id mid; @messages.member?(mid) && @messages[mid].root.thread end def contains_id? id; @messages.member?(id) && !@messages[id].empty? end def thread_for m; thread_for_id m.id end def contains? m; contains_id? m.id end def threads; @threads.values end @@ -322,11 +322,11 @@ end ## load in (at most) num number of threads from the index def load_n_threads num, opts={} @index.each_id_by_date opts do |mid, builder| - break if size >= num + break if size >= num unless num == -1 next if contains_id? mid m = builder.call load_thread_for_message m, :skip_killed => opts[:skip_killed], :load_deleted => opts[:load_deleted], :load_spam => opts[:load_spam] yield size if block_given? @@ -413,17 +413,11 @@ ## check to see if the subject is still the same (in the case ## that we first added a child message with a different ## subject) if root.thread - unless @threads[key] == root.thread - if @threads[key] - root.thread.empty! - @threads[key] << root - root.thread = @threads[key] - else - @threads[key] = root.thread - end + if @threads.member?(key) && @threads[key] != root.thread + @threads.delete key end else thread = @threads[key] thread << root root.thread = thread