Class: Mailboxer::Notification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mailboxer::Notification
- Defined in:
- app/models/mailboxer/notification.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#recipients ⇒ Object
Returns the recipients of the Notification.
Class Method Summary collapse
-
.notify_all(recipients, subject, body, obj = nil, sanitize_text = true, notification_code = nil, send_mail = true) ⇒ Object
Sends a Notification to all the recipients.
-
.successful_delivery?(receipts) ⇒ Boolean
Takes a
Receipt
or anArray
of them and returnstrue
if the delivery was successful orfalse
if some error raised.
Instance Method Summary collapse
-
#clean ⇒ Object
Sanitizes the body and subject.
-
#deliver(should_clean = true, send_mail = true) ⇒ Object
Delivers a Notification.
- #expire ⇒ Object
- #expire! ⇒ Object
- #expired? ⇒ Boolean
-
#is_deleted?(participant) ⇒ Boolean
Returns if the participant have deleted the Notification.
- #is_read?(participant) ⇒ Boolean
-
#is_trashed?(participant) ⇒ Boolean
Returns if the participant have trashed the Notification.
-
#is_unread?(participant) ⇒ Boolean
Returns if the participant have read the Notification.
-
#mark_as_deleted(participant) ⇒ Object
Mark the notification as deleted for one of the participant.
-
#mark_as_read(participant) ⇒ Object
Mark the notification as read.
-
#mark_as_unread(participant) ⇒ Object
Mark the notification as unread.
-
#move_to_trash(participant) ⇒ Object
Move the notification to the trash.
-
#object ⇒ Object
Returns notified_object.
-
#receipt_for(participant) ⇒ Object
Returns the receipt for the participant.
-
#receipts_for(participant) ⇒ Object
Returns the receipt for the participant.
- #sanitize(text) ⇒ Object
-
#untrash(participant) ⇒ Object
Takes the notification out of the trash.
Instance Attribute Details
#recipients ⇒ Object
Returns the recipients of the Notification
96 97 98 |
# File 'app/models/mailboxer/notification.rb', line 96 def recipients @recipients end |
Class Method Details
.notify_all(recipients, subject, body, obj = nil, sanitize_text = true, notification_code = nil, send_mail = true) ⇒ Object
Sends a Notification to all the recipients
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/mailboxer/notification.rb', line 36 def notify_all(recipients, subject, body, obj = nil, sanitize_text = true, notification_code=nil, send_mail=true) notification = Mailboxer::NotificationBuilder.new({ :recipients => recipients, :subject => subject, :body => body, :notified_object => obj, :notification_code => notification_code }).build notification.deliver sanitize_text, send_mail end |
.successful_delivery?(receipts) ⇒ Boolean
Takes a Receipt
or an Array
of them and returns true
if the delivery was successful or false
if some error raised
50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/mailboxer/notification.rb', line 50 def successful_delivery? receipts case receipts when Mailboxer::Receipt receipts.valid? when Array receipts.all?(&:valid?) else false end end |
Instance Method Details
#clean ⇒ Object
Sanitizes the body and subject
164 165 166 167 |
# File 'app/models/mailboxer/notification.rb', line 164 def clean self.subject = sanitize(subject) if subject self.body = sanitize(body) end |
#deliver(should_clean = true, send_mail = true) ⇒ Object
Delivers a Notification. USE NOT RECOMENDED. Use Mailboxer::Models::Message.notify and Notification.notify_all instead.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/mailboxer/notification.rb', line 81 def deliver(should_clean = true, send_mail = true) clean if should_clean temp_receipts = recipients.map { |r| build_receipt(r, nil, false) } if temp_receipts.all?(&:valid?) temp_receipts.each(&:save!) #Save receipts Mailboxer::MailDispatcher.new(self, recipients).call if send_mail self.recipients = nil end return temp_receipts if temp_receipts.size > 1 temp_receipts.first end |
#expire ⇒ Object
73 74 75 76 77 |
# File 'app/models/mailboxer/notification.rb', line 73 def expire unless expired? self.expires = Time.now - 1.second end end |
#expire! ⇒ Object
66 67 68 69 70 71 |
# File 'app/models/mailboxer/notification.rb', line 66 def expire! unless expired? expire save end end |
#expired? ⇒ Boolean
62 63 64 |
# File 'app/models/mailboxer/notification.rb', line 62 def expired? expires.present? && (expires < Time.now) end |
#is_deleted?(participant) ⇒ Boolean
Returns if the participant have deleted the Notification
128 129 130 131 |
# File 'app/models/mailboxer/notification.rb', line 128 def is_deleted?(participant) return false if participant.nil? return receipt_for(participant).first.deleted end |
#is_read?(participant) ⇒ Boolean
117 118 119 |
# File 'app/models/mailboxer/notification.rb', line 117 def is_read?(participant) !is_unread?(participant) end |
#is_trashed?(participant) ⇒ Boolean
Returns if the participant have trashed the Notification
122 123 124 125 |
# File 'app/models/mailboxer/notification.rb', line 122 def is_trashed?(participant) return false if participant.nil? receipt_for(participant).first.trashed end |
#is_unread?(participant) ⇒ Boolean
Returns if the participant have read the Notification
112 113 114 115 |
# File 'app/models/mailboxer/notification.rb', line 112 def is_unread?(participant) return false if participant.nil? !receipt_for(participant).first.is_read end |
#mark_as_deleted(participant) ⇒ Object
Mark the notification as deleted for one of the participant
158 159 160 161 |
# File 'app/models/mailboxer/notification.rb', line 158 def mark_as_deleted(participant) return if participant.nil? return receipt_for(participant).mark_as_deleted end |
#mark_as_read(participant) ⇒ Object
Mark the notification as read
134 135 136 137 |
# File 'app/models/mailboxer/notification.rb', line 134 def mark_as_read(participant) return if participant.nil? receipt_for(participant).mark_as_read end |
#mark_as_unread(participant) ⇒ Object
Mark the notification as unread
140 141 142 143 |
# File 'app/models/mailboxer/notification.rb', line 140 def mark_as_unread(participant) return if participant.nil? receipt_for(participant).mark_as_unread end |
#move_to_trash(participant) ⇒ Object
Move the notification to the trash
146 147 148 149 |
# File 'app/models/mailboxer/notification.rb', line 146 def move_to_trash(participant) return if participant.nil? receipt_for(participant).move_to_trash end |
#object ⇒ Object
Returns notified_object. DEPRECATED
170 171 172 173 |
# File 'app/models/mailboxer/notification.rb', line 170 def object warn "DEPRECATION WARNING: use 'notified_object' instead of 'object' to get the object associated with the Notification" notified_object end |
#receipt_for(participant) ⇒ Object
Returns the receipt for the participant
102 103 104 |
# File 'app/models/mailboxer/notification.rb', line 102 def receipt_for(participant) Mailboxer::Receipt.notification(self).recipient(participant) end |
#receipts_for(participant) ⇒ Object
Returns the receipt for the participant. Alias for receipt_for(participant)
107 108 109 |
# File 'app/models/mailboxer/notification.rb', line 107 def receipts_for(participant) receipt_for(participant) end |
#sanitize(text) ⇒ Object
175 176 177 |
# File 'app/models/mailboxer/notification.rb', line 175 def sanitize(text) ::Mailboxer::Cleaner.instance.sanitize(text) end |
#untrash(participant) ⇒ Object
Takes the notification out of the trash
152 153 154 155 |
# File 'app/models/mailboxer/notification.rb', line 152 def untrash(participant) return if participant.nil? receipt_for(participant).untrash end |