Skip to content

Commit 7960134

Browse files
committed
Message#children
1 parent 8a29b98 commit 7960134

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

app/models/message.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Message < ApplicationRecord
1010
# https://blade.ruby-lang.org/ruby-talk/410000 is not.
1111
self.skip_time_zone_conversion_for_attributes = [:published_at]
1212

13+
attr_accessor :children
14+
1315
class << self
1416
def from_mail(mail, list, list_seq)
1517
body = Kconv.toutf8 mail.body.raw_source
@@ -85,6 +87,10 @@ def from_string(str)
8587
end
8688
end
8789

90+
def count_recursively(count = 0)
91+
count + 1 + (children&.sum(&:count_recursively) || 0)
92+
end
93+
8894
def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
8995
m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client)
9096

0 commit comments

Comments
 (0)