X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fthread.rb;h=2300305c0710da7dfcb55891b5967abdc27e7f8f;hb=refs%2Fheads%2Fnext;hp=d395c3588f7274448dc86d2d784ee9021b29c3b0;hpb=8ee91effe23a42d483fa6c0d2106ff328d3ba686;p=sup diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb index d395c35..2300305 100644 --- a/lib/sup/thread.rb +++ b/lib/sup/thread.rb @@ -24,6 +24,8 @@ ## a faked root object tying them all together into one tree ## structure. +require 'set' + module Redwood class Thread @@ -101,17 +103,16 @@ class Thread def toggle_label label if has_label? label remove_label label - return false + false else apply_label label - return true + true end end def set_labels l; each { |m, *o| m && m.labels = l }; end - def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end - def save index; each { |m, *o| m && m.save(index) }; end + def save_state index; each { |m, *o| m && m.save_state(index) }; end def direct_participants map { |m, *o| [m.from] + m.to if m }.flatten.compact.uniq @@ -123,15 +124,14 @@ class Thread def size; map { |m, *o| m ? 1 : 0 }.sum; end def subj; argfind { |m, *o| m && m.subj }; end - def labels - map { |m, *o| m && m.labels }.flatten.compact.uniq.sort_by { |t| t.to_s } - end + def labels; inject(Set.new) { |s, (m, *o)| m ? s | m.labels : s } end def labels= l - each { |m, *o| m && m.labels = l.clone } + raise ArgumentError, "not a set" unless l.is_a?(Set) + each { |m, *o| m && m.labels = l.dup } end def latest_message - inject(nil) do |a, b| + inject(nil) do |a, b| b = b.first if a.nil? b @@ -162,7 +162,7 @@ class Container @id = id @message, @parent, @thread = nil, nil, nil @children = [] - end + end def each_with_stuff parent=nil yield self, 0, parent @@ -357,7 +357,7 @@ class ThreadSet return if threads.size < 2 containers = threads.map do |t| - c = @messages.member?(c) ? @messages[t.first.id] : nil + c = @messages.member?(t.first.id) ? @messages[t.first.id] : nil raise "not in threadset: #{t.first.id}" unless c && c.message c end