Set mention notification as read when viewing post
- If a mention for the current user and the displayed post exists,
mark it as read
- Use set_read_state instead of manually setting unread as false
This commit is contained in:
parent
773340de67
commit
48a3909fe0
1 changed files with 7 additions and 3 deletions
|
|
@ -85,9 +85,13 @@ class PostsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_corresponding_notifications_read
|
def mark_corresponding_notifications_read
|
||||||
Notification.where(recipient_id: current_user.id, target_id: @post.id, unread: true).each do |n|
|
# For comments, reshares, likes
|
||||||
n.unread = false
|
Notification.where(recipient_id: current_user.id, target_type: "Post", target_id: @post.id, unread: true).each do |n|
|
||||||
n.save!
|
n.set_read_state( true )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For mentions
|
||||||
|
mention = @post.mentions.where(person_id: current_user.id).first
|
||||||
|
Notification.where(recipient_id: current_user.id, target_type: "Mention", target_id: mention.id, unread: true).first.try(:set_read_state, true) if mention
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue