Files
fizzy/app/models/notification.rb
T
2025-01-16 17:48:38 +00:00

19 lines
473 B
Ruby

class Notification < ApplicationRecord
belongs_to :user
belongs_to :event
belongs_to :bubble
belongs_to :resource, polymorphic: true
scope :unread, -> { where(read_at: nil) }
scope :read, -> { where.not(read_at: nil) }
scope :ordered, -> { order(read_at: :desc, created_at: :desc) }
delegate :creator, to: :event
broadcasts_to ->(notification) { [ notification.user, :notifications ] }, inserts_by: :prepend
def read?
read_at.present?
end
end