Fix: dismiss mention notifications in cards and comments when reading a card
This commit is contained in:
@@ -2,7 +2,6 @@ class Cards::ReadingsController < ApplicationController
|
||||
include CardScoped
|
||||
|
||||
def create
|
||||
@notifications = Current.user.notifications.where(source: @card.events)
|
||||
@notifications.each(&:read)
|
||||
@notifications = @card.read_by(Current.user)
|
||||
end
|
||||
end
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
class Card < ApplicationRecord
|
||||
include Assignable, Colored, Engageable, Eventable, Golden, Mentions,
|
||||
Messages, Pinnable, Closeable, Searchable, Staged, Statuses, Taggable, Watchable
|
||||
Messages, Pinnable, Closeable, Readable, Searchable, Staged,
|
||||
Statuses, Taggable, Watchable
|
||||
|
||||
belongs_to :collection, touch: true
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
module Card::Readable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def read_by(user)
|
||||
notifications_for(user).tap do |notifications|
|
||||
notifications.each(&:read)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def notifications_for(user)
|
||||
user.notifications.unread.where(source: notification_sources)
|
||||
end
|
||||
|
||||
def notification_sources
|
||||
events + mentions + comment_mentions
|
||||
end
|
||||
|
||||
def comment_mentions
|
||||
Mention.where(source: comments)
|
||||
end
|
||||
|
||||
def comments
|
||||
Comment.where(id: messages.comments.pluck(:messageable_id))
|
||||
end
|
||||
end
|
||||
Vendored
+6
-1
@@ -1,4 +1,9 @@
|
||||
logo_card_david_mention_by_jz:
|
||||
source: logo (card)
|
||||
source: logo (Card)
|
||||
mentioner: jz
|
||||
mentionee: david
|
||||
|
||||
logo_comment_david_mention_by_jz:
|
||||
source: logo_agreement_jz (Comment)
|
||||
mentioner: jz
|
||||
mentionee: david
|
||||
|
||||
Vendored
+12
@@ -15,3 +15,15 @@ layout_commented_kevin:
|
||||
source: layout_commented (Event)
|
||||
created_at: <%= 1.week.ago %>
|
||||
creator: david
|
||||
|
||||
logo_card_david_mention_by_jz:
|
||||
user: david
|
||||
source: logo_card_david_mention_by_jz (Mention)
|
||||
created_at: <%= 1.week.ago %>
|
||||
creator: david
|
||||
|
||||
logo_comment_david_mention_by_jz:
|
||||
user: david
|
||||
source: logo_comment_david_mention_by_jz (Mention)
|
||||
created_at: <%= 1.week.ago %>
|
||||
creator: david
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
require "test_helper"
|
||||
|
||||
class Card::ReadableTest < ActiveSupport::TestCase
|
||||
test "read clears events notifications" do
|
||||
assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do
|
||||
assert_changes -> { notifications(:logo_assignment_kevin).reload.read? }, from: false, to: true do
|
||||
cards(:logo).read_by(users(:kevin))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "read clear mentions in the description" do
|
||||
assert_changes -> { notifications(:logo_card_david_mention_by_jz).reload.read? }, from: false, to: true do
|
||||
cards(:logo).read_by(users(:david))
|
||||
end
|
||||
end
|
||||
|
||||
test "read clear mentions in comments" do
|
||||
assert_changes -> { notifications(:logo_comment_david_mention_by_jz).reload.read? }, from: false, to: true do
|
||||
cards(:logo).read_by(users(:david))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,8 @@ class User::MentionableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "mentioned by" do
|
||||
users(:david).mentions.destroy_all
|
||||
|
||||
assert_difference -> { users(:david).mentions.count }, +1 do
|
||||
users(:david).mentioned_by users(:jz), at: cards(:logo)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user