From mboxrd@z Thu Jan 1 00:00:00 1970 From: rlane@club.cc.cmu.edu (Rich Lane) Date: Sat, 20 Jun 2009 13:50:16 -0700 Subject: [sup-talk] [PATCH 17/18] add limit argument to author_names_and_newness_for_thread In-Reply-To: <1245531017-9907-17-git-send-email-rlane@club.cc.cmu.edu> References: <1245531017-9907-1-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-2-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-3-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-4-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-5-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-6-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-7-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-8-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-9-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-10-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-11-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-12-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-13-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-14-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-15-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-16-git-send-email-rlane@club.cc.cmu.edu> <1245531017-9907-17-git-send-email-rlane@club.cc.cmu.edu> Message-ID: <1245531017-9907-18-git-send-email-rlane@club.cc.cmu.edu> --- lib/sup/modes/thread-index-mode.rb | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 0bd8110..b671119 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -1,3 +1,5 @@ +require 'set' + module Redwood ## subclasses should implement: @@ -757,10 +759,12 @@ protected def authors; map { |m, *o| m.from if m }.compact.uniq; end - def author_names_and_newness_for_thread t + def author_names_and_newness_for_thread t, limit=nil new = {} - authors = t.map do |m, *o| + authors = Set.new + t.each do |m, *o| next unless m + break if limit and authors.size >= limit name = if AccountManager.is_account?(m.from) @@ -772,12 +776,13 @@ protected end new[name] ||= m.has_label?(:unread) - name + authors << name end - authors.compact.uniq.map { |a| [a, new[a]] } + authors.to_a.map { |a| [a, new[a]] } end + AUTHOR_LIMIT = 5 def text_for_thread_at line t, size_widget = @mutex.synchronize { [@threads[line], @size_widgets[line]] } @@ -787,7 +792,7 @@ protected ## format the from column cur_width = 0 - ann = author_names_and_newness_for_thread t + ann = author_names_and_newness_for_thread t, AUTHOR_LIMIT from = [] ann.each_with_index do |(name, newness), i| break if cur_width >= from_width -- 1.6.0.4