Ensure caching timestamp is updated when marking notifications as read

This commit is contained in:
Karina Kwiatek 2023-06-16 18:20:21 +02:00
parent 5a3f65e39a
commit bcfb215f8c
2 changed files with 8 additions and 4 deletions

View File

@ -51,11 +51,12 @@ class AnswerController < ApplicationController
private
def mark_notifications_as_read
Notification.where(recipient_id: current_user.id, new: true)
updated = Notification.where(recipient_id: current_user.id, new: true)
.and(Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id)
.or(Notification.where(type: "Notification::Commented", target_id: @answer.comments.pluck(:id)))
.or(Notification.where(type: "Notification::Smiled", target_id: @answer.smiles.pluck(:id)))
.or(Notification.where(type: "Notification::CommentSmiled", target_id: @answer.comment_smiles.pluck(:id))))
.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
current_user.touch(:notifications_updated_at) if updated.positive?
end
end

View File

@ -21,9 +21,12 @@ class Settings::ExportController < ApplicationController
private
# rubocop:disable Rails/SkipsModelValidations
def mark_notifications_as_read
Notification::DataExported
.where(recipient: current_user, new: true)
.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
updated = Notification::DataExported
.where(recipient: current_user, new: true)
.update_all(new: false)
current_user.touch(:notifications_updated_at) if updated.positive?
end
# rubocop:enable Rails/SkipsModelValidations
end