diff --git a/app/models/card.rb b/app/models/card.rb index 09d2c0314..3688ef4e9 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -1,5 +1,5 @@ class Card < ApplicationRecord - include Assignable, Boostable, Colored, Engageable, Eventable, Golden, + include Assignable, Boostable, Colored, DraftCommentable, Engageable, Eventable, Golden, Messages, Notifiable, Pinnable, Closeable, Scorable, Searchable, Staged, Statuses, Taggable, Watchable diff --git a/app/models/card/draft_commentable.rb b/app/models/card/draft_commentable.rb new file mode 100644 index 000000000..c0e832e6f --- /dev/null +++ b/app/models/card/draft_commentable.rb @@ -0,0 +1,33 @@ +module Card::DraftCommentable + extend ActiveSupport::Concern + + included do + after_save :capture_draft_comment + end + + def draft_comment + find_or_build_initial_comment.body.content + end + + def draft_comment=(body) + if body.present? + @draft_comment = body + else + messages.comments.destroy_all + end + end + + private + def find_or_build_initial_comment + message = messages.comments.first || messages.new(messageable: Comment.new) + message.comment + end + + def capture_draft_comment + if @draft_comment.present? + find_or_build_initial_comment.update! body: @draft_comment, creator: creator + end + @draft_comment = nil + end +end + diff --git a/app/models/card/messages.rb b/app/models/card/messages.rb index 01446905c..89579b78f 100644 --- a/app/models/card/messages.rb +++ b/app/models/card/messages.rb @@ -3,35 +3,9 @@ module Card::Messages included do has_many :messages, -> { chronologically }, dependent: :destroy - after_save :capture_draft_comment end def capture(messageable) messages.create! messageable: messageable end - - def draft_comment - find_or_build_initial_comment.body.content - end - - def draft_comment=(body) - if body.present? - @draft_comment = body - else - messages.comments.destroy_all - end - end - - private - def find_or_build_initial_comment - message = messages.comments.first || messages.new(messageable: Comment.new) - message.comment - end - - def capture_draft_comment - if @draft_comment.present? - find_or_build_initial_comment.update! body: @draft_comment, creator: creator - end - @draft_comment = nil - end end