Class: Notification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Notification
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/models/notification.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#recipients ⇒ Object
Returns the recipients of the Notification.
Class Method Summary collapse
-
.notify_all(recipients, subject, body) ⇒ Object
Sends a Notification to all the recipients.
Instance Method Summary collapse
-
#clean ⇒ Object
Sanitizes the body and subject.
-
#deliver(should_clean = true) ⇒ Object
Delivers a Notification.
-
#is_unread?(participant) ⇒ Boolean
Returns if the participant have read the Notification.
-
#receipt_for(participant) ⇒ Object
Returns the receipt for the participant.
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
4 5 6 |
# File 'app/models/notification.rb', line 4 def object @object end |
#recipients ⇒ Object
Returns the recipients of the Notification
49 50 51 |
# File 'app/models/notification.rb', line 49 def recipients @recipients end |
Class Method Details
.notify_all(recipients, subject, body) ⇒ Object
Sends a Notification to all the recipients
15 16 17 18 19 20 |
# File 'app/models/notification.rb', line 15 def notify_all(recipients,subject,body) notification = Notification.new({:body => body, :subject => subject}) notification.recipients = recipients.is_a?(Array) ? recipients : [recipients] notification.recipients = notification.recipients.uniq return notification.deliver end |
Instance Method Details
#clean ⇒ Object
Sanitizes the body and subject
74 75 76 77 78 79 |
# File 'app/models/notification.rb', line 74 def clean unless self.subject.nil? self.subject = sanitize self.subject end self.body = sanitize self.body end |
#deliver(should_clean = true) ⇒ Object
Delivers a Notification. USE NOT RECOMENDED. Use Mailboxer::Models::Message.notify and Notification.notify_all instead.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/notification.rb', line 25 def deliver(should_clean = true) self.clean if should_clean temp_receipts = Array.new #Receiver receipts self.recipients.each do |r| msg_receipt = Receipt.new msg_receipt.notification = self msg_receipt.read = false msg_receipt.receiver = r temp_receipts << msg_receipt #Should send an email? if r.should_email? self NotificationMailer.send_email(self,r).deliver end end temp_receipts.each(&:valid?) if temp_receipts.all? { |t| t.errors.empty? } temp_receipts.each(&:save!) #Save receipts self.recipients=nil end return temp_receipts end |
#is_unread?(participant) ⇒ Boolean
Returns if the participant have read the Notification
66 67 68 69 |
# File 'app/models/notification.rb', line 66 def is_unread?(participant) return false if participant.nil? return self.receipt_for(participant).unread.count!=0 end |
#receipt_for(participant) ⇒ Object
Returns the receipt for the participant
61 62 63 |
# File 'app/models/notification.rb', line 61 def receipt_for(participant) return Receipt.notification(self).receiver(participant) end |