Method: Redwood::Thread#each

Defined in:
lib/sup/thread.rb

#each(fake_root = false) ⇒ Object

yields each message, its depth, and its parent. the message yield parameter can be a Message object, or :fake_root, or nil (no message found but the presence of one deduced from other messages).



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/sup/thread.rb', line 63

def each fake_root=false
  adj = 0
  root = @containers.find_all { |c| c.message && !Message.subj_is_reply?(c.message.subj) }.argmin { |c| c.date }

  if root
    adj = 1
    root.first_useful_descendant.each_with_stuff do |c, d, par|
      yield c.message, d, (par ? par.message : nil)
    end
  elsif @containers.length > 1 && fake_root
    adj = 1
    yield :fake_root, 0, nil
  end

  @containers.each do |cont|
    next if cont == root
    fud = cont.first_useful_descendant
    fud.each_with_stuff do |c, d, par|
      ## special case here: if we're an empty root that's already
      ## been joined by a fake root, don't emit
      yield c.message, d + adj, (par ? par.message : nil) unless
        fake_root && c.message.nil? && root.nil? && c == fud
    end
  end
end