chore: mark conversation notifications as read on visit (#13906)
This commit is contained in:
25
app/services/notification/mark_conversation_read_service.rb
Normal file
25
app/services/notification/mark_conversation_read_service.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class Notification::MarkConversationReadService
|
||||
pattr_initialize [:user!, :account!, :conversation!]
|
||||
|
||||
def perform
|
||||
return unless user.is_a?(User)
|
||||
|
||||
notifications.find_each do |notification|
|
||||
notification.update!(read_at: read_at)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notifications
|
||||
user.notifications.where(
|
||||
account: account,
|
||||
primary_actor: conversation,
|
||||
read_at: nil
|
||||
)
|
||||
end
|
||||
|
||||
def read_at
|
||||
@read_at ||= Time.current
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user