Class: UserNotification

Inherits:
ApplicationRecord show all
Defined in:
app/models/user_notification.rb

Overview

The user level notification. This is meant to be called by the Notifications Framework

Class Method Summary collapse

Class Method Details

.next_unread_popup_for(course_user) ⇒ UserNotification|nil

Returns the oldest unread popup notification for the given course user. Popups with deleted objects will trigger destruction of that +Activity+ object. +nil+ is returned if all popups are read.


21
22
23
24
25
26
27
28
29
# File 'app/models/user_notification.rb', line 21

def self.next_unread_popup_for(course_user)
  popup.where(user: course_user.user).ordered_by_updated_at.
    includes(activity: { object: :course }).unread_by(course_user.user).
    find do |popup|
      present = popup.activity.object.present?
      popup.activity.destroy unless present
      present && popup.activity.from_course?(course_user.course)
    end
end