commit 4393104e5fcf763630588fc39feaecf94e147120
parent ee9725c21f2fe2060704f9df065bd3ce4a784825
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Wed, 30 Sep 2009 11:31:46 -0400
display author names in order in thread-index-mode
Also fix a minor bug where author newness was not being correctly calculated
for large threads.
Diffstat:
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -66,7 +66,7 @@ EOS
@date_width = DATE_WIDTH
@interrupt_search = false
-
+
initialize_threads # defines @ts and @ts_mutex
update # defines @text and @lines
@@ -759,30 +759,36 @@ protected
@lines = threads.map_with_index { |t, i| [t, i] }.to_h
buffer.mark_dirty if buffer
end
-
+
def authors; map { |m, *o| m.from if m }.compact.uniq; end
+ ## preserve author order from the thread
def author_names_and_newness_for_thread t, limit=nil
new = {}
- 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)
- "me"
- elsif t.authors.size == 1
- m.from.mediumname
- else
- m.from.shortname
- end
+ seen = {}
+ authors = t.map do |m, *o|
+ next unless m && m.from
+ new[m.from] ||= m.has_label?(:unread)
+ next if seen[m.from]
+ seen[m.from] = true
+ m.from
+ end.compact
+
+ result = []
+ authors.each do |a|
+ break if limit && result.size >= limit
+ name = if AccountManager.is_account?(a)
+ "me"
+ elsif t.authors.size == 1
+ a.mediumname
+ else
+ a.shortname
+ end
- new[name] ||= m.has_label?(:unread)
- authors << name
+ result << [name, new[a]]
end
- authors.to_a.map { |a| [a, new[a]] }
+ result
end
AUTHOR_LIMIT = 5