diff --git a/app/models/card/readable.rb b/app/models/card/readable.rb index 2511a6b45..652bb2fce 100644 --- a/app/models/card/readable.rb +++ b/app/models/card/readable.rb @@ -13,7 +13,19 @@ module Card::Readable end def notification_sources - events + mentions + comment_mentions + event_notification_sources + mention_notification_sources + end + + def event_notification_sources + events + comment_creation_events + end + + def mention_notification_sources + mentions + comment_mentions + end + + def comment_creation_events + Event.where(eventable: comments) end def comment_mentions @@ -21,6 +33,6 @@ module Card::Readable end def comments - Comment.where(id: messages.comments.pluck(:messageable_id)) + @comments ||= Comment.where(id: messages.comments.pluck(:messageable_id)) end end diff --git a/test/models/card/readable_test.rb b/test/models/card/readable_test.rb index b60d98a09..c53d3f44d 100644 --- a/test/models/card/readable_test.rb +++ b/test/models/card/readable_test.rb @@ -20,4 +20,10 @@ class Card::ReadableTest < ActiveSupport::TestCase cards(:logo).read_by(users(:david)) end end + + test "read clears notifications from the comments" do + assert_changes -> { notifications(:layout_commented_kevin).reload.read? }, from: false, to: true do + cards(:layout).read_by(users(:kevin)) + end + end end