forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification.rb
More file actions
39 lines (31 loc) · 1014 Bytes
/
notification.rb
File metadata and controls
39 lines (31 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Notification < ActiveRecord::Base
attr_accessible :title, :message, :notification_type, :ack_at, :user_id
belongs_to :user
scope :unacked, :conditions => {:ack_at => nil}, :order => 'created_at DESC'
default_scope unacked
validates :user, :presence => true
# Calls #publish! on the user after creation to push to the frontend
after_create :publish!
def publish!
user.publish!
end
# Acknowledge the notification, do not display again
# Note: later on, we'll likely have a list of old notifications somewhere
# obviously it should be displayed there then.
def ack!
update_attribute(:ack_at, Time.now)
end
def ack?
ack_at ? true : false
end
# Default type to 'info' for now
def notification_type
read_attribute(:notification_type) || 'info'
end
# Return Jbuilder for serialization
def to_builder(builder = nil)
builder ||= Jbuilder.new
builder.(self, :id, :title, :message, :notification_type, :ack_at, :user_id)
builder
end
end