Class: Alerter::Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Alerter::Message
- Defined in:
- app/models/alerter/message.rb
Instance Attribute Summary collapse
-
#recipients ⇒ Object
Returns the recipients of the Notification.
Class Method Summary collapse
- .message_all(recipients, short_msg, long_msg, notification_type_name, sanitize_text = true) ⇒ Object
Instance Method Summary collapse
-
#clean ⇒ Object
Sanitizes the body and subject.
-
#deliver(should_clean = 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_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_not_deleted(participant) ⇒ Object
Mark the notification as not 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.
-
#receipt_for(participant) ⇒ Object
Returns the receipt for the participant.
-
#receipts_for(participant) ⇒ Object
Returns the receipt for the participant.
- #sanitize(text) ⇒ Object
Instance Attribute Details
#recipients ⇒ Object
Returns the recipients of the Notification
92 93 94 |
# File 'app/models/alerter/message.rb', line 92 def recipients @recipients end |
Class Method Details
.message_all(recipients, short_msg, long_msg, notification_type_name, sanitize_text = true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/alerter/message.rb', line 47 def (recipients, short_msg, long_msg, notification_type_name, sanitize_text = true) = Alerter::MessageBuilder.new({ :recipients => recipients, :short_msg => short_msg, :long_msg => long_msg, :notification_type => Alerter::NotificationType.find_or_create_by(name: notification_type_name), }).build .save! .deliver sanitize_text end |
Instance Method Details
#clean ⇒ Object
Sanitizes the body and subject
150 151 152 153 |
# File 'app/models/alerter/message.rb', line 150 def clean self.short_msg = sanitize(short_msg) self.long_msg = sanitize(long_msg) end |
#deliver(should_clean = true) ⇒ Object
Delivers a Notification. USE NOT RECOMENDED. Use Alerter::Models::Message.notify and Notification.notify_all instead.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/alerter/message.rb', line 78 def deliver(should_clean = true) clean if should_clean temp_receipts = recipients.map { |r| build_receipt(r, 'inbox', false) } if temp_receipts.all?(&:valid?) temp_receipts.each(&:save!) #Save receipts Alerter::MessageDispatcher.new(self, recipients).call #self.recipients = nil end return temp_receipts if temp_receipts.size > 1 temp_receipts.first end |
#expire ⇒ Object
70 71 72 73 74 |
# File 'app/models/alerter/message.rb', line 70 def expire unless expired? self.expires = Time.now - 1.second end end |
#expire! ⇒ Object
63 64 65 66 67 68 |
# File 'app/models/alerter/message.rb', line 63 def expire! unless expired? expire save end end |
#expired? ⇒ Boolean
59 60 61 |
# File 'app/models/alerter/message.rb', line 59 def expired? expires.present? && (expires < Time.now) end |
#is_deleted?(participant) ⇒ Boolean
Returns if the participant have deleted the Notification
119 120 121 122 |
# File 'app/models/alerter/message.rb', line 119 def is_deleted?(participant) return false if participant.nil? return receipt_for(participant).first.deleted end |
#is_read?(participant) ⇒ Boolean
114 115 116 |
# File 'app/models/alerter/message.rb', line 114 def is_read?(participant) !is_unread?(participant) end |
#is_unread?(participant) ⇒ Boolean
Returns if the participant have read the Notification
109 110 111 112 |
# File 'app/models/alerter/message.rb', line 109 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
138 139 140 141 |
# File 'app/models/alerter/message.rb', line 138 def mark_as_deleted(participant) return if participant.nil? return receipt_for(participant).mark_as_deleted end |
#mark_as_not_deleted(participant) ⇒ Object
Mark the notification as not deleted for one of the participant
144 145 146 147 |
# File 'app/models/alerter/message.rb', line 144 def mark_as_not_deleted(participant) return if participant.nil? return receipt_for(participant).mark_as_not_deleted end |
#mark_as_read(participant) ⇒ Object
Mark the notification as read
125 126 127 128 |
# File 'app/models/alerter/message.rb', line 125 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
131 132 133 134 |
# File 'app/models/alerter/message.rb', line 131 def mark_as_unread(participant) return if participant.nil? receipt_for(participant).mark_as_unread end |
#receipt_for(participant) ⇒ Object
Returns the receipt for the participant
98 99 100 101 |
# File 'app/models/alerter/message.rb', line 98 def receipt_for(participant) #Alerter::Receipt.notification(self).recipient(participant) self.receipts.recipient(participant) end |
#receipts_for(participant) ⇒ Object
Returns the receipt for the participant. Alias for receipt_for(participant)
104 105 106 |
# File 'app/models/alerter/message.rb', line 104 def receipts_for(participant) receipt_for(participant) end |