Class: Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Message
- Defined in:
- app/models/message.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active_readers ⇒ Object
- #administrative? ⇒ Boolean
- #deliver(readers) ⇒ Object
- #deliver_to(reader, sender = nil) ⇒ Object
- #delivered? ⇒ Boolean
- #delivered_to?(reader) ⇒ Boolean
- #delivery_to(reader) ⇒ Object
- #filtered_body ⇒ Object
- #function ⇒ Object
- #has_function? ⇒ Boolean
- #inactive_readers ⇒ Object
- #possible_readers ⇒ Object
- #preview(reader = nil) ⇒ Object
- #published! ⇒ Object
- #published? ⇒ Boolean
- #record_delivery(reader) ⇒ Object
- #status ⇒ Object
- #status=(value) ⇒ Object
- #undelivered_readers ⇒ Object
Class Method Details
.functional(function, group = nil) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/models/message.rb', line 66 def self.functional(function, group=nil) = for_function(function) if group .belonging_to(group).first else .ungrouped.first end end |
Instance Method Details
#active_readers ⇒ Object
50 51 52 |
# File 'app/models/message.rb', line 50 def active_readers possible_readers.active end |
#administrative? ⇒ Boolean
77 78 79 |
# File 'app/models/message.rb', line 77 def administrative? has_function? end |
#deliver(readers) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'app/models/message.rb', line 94 def deliver(readers) failures = [] readers.each do |reader| failures.push(reader) unless deliver_to(reader) end self.published! failures end |
#deliver_to(reader, sender = nil) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'app/models/message.rb', line 103 def deliver_to(reader, sender=nil) ReaderNotifier.(reader, self, sender) record_delivery(reader) true rescue => e Rails.logger.warn "@@ delivery failed: #{e.inspect}" raise end |
#delivered? ⇒ Boolean
54 55 56 |
# File 'app/models/message.rb', line 54 def delivered? deliveries.any? end |
#delivered_to?(reader) ⇒ Boolean
116 117 118 |
# File 'app/models/message.rb', line 116 def delivered_to?(reader) recipients.include?(reader) end |
#delivery_to(reader) ⇒ Object
120 121 122 |
# File 'app/models/message.rb', line 120 def delivery_to(reader) deliveries.to_reader(reader).first if delivered_to?(reader) end |
#filtered_body ⇒ Object
30 31 32 |
# File 'app/models/message.rb', line 30 def filtered_body filter.filter(body) end |
#function ⇒ Object
63 64 65 |
# File 'app/models/message.rb', line 63 def function MessageFunction[self.function_id] end |
#has_function? ⇒ Boolean
74 75 76 |
# File 'app/models/message.rb', line 74 def has_function? !function.nil? end |
#inactive_readers ⇒ Object
46 47 48 |
# File 'app/models/message.rb', line 46 def inactive_readers possible_readers.inactive end |
#possible_readers ⇒ Object
34 35 36 |
# File 'app/models/message.rb', line 34 def possible_readers permitted_readers end |
#preview(reader = nil) ⇒ Object
58 59 60 61 |
# File 'app/models/message.rb', line 58 def preview(reader=nil) reader ||= possible_readers.first || Reader.for_user(Reader.current) ReaderNotifier.(reader, self) end |
#published! ⇒ Object
90 91 92 |
# File 'app/models/message.rb', line 90 def published! status = Status[:published] end |
#published? ⇒ Boolean
87 88 89 |
# File 'app/models/message.rb', line 87 def published? status == Status[:published] end |
#record_delivery(reader) ⇒ Object
112 113 114 |
# File 'app/models/message.rb', line 112 def record_delivery(reader) MessageReader.(self.id, reader.id).update_attribute(:sent_at, Time.now) end |
#status ⇒ Object
81 82 83 |
# File 'app/models/message.rb', line 81 def status Status.find(self.status_id) end |
#status=(value) ⇒ Object
84 85 86 |
# File 'app/models/message.rb', line 84 def status=(value) self.status_id = value.id end |
#undelivered_readers ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/models/message.rb', line 38 def undelivered_readers if recipients.any? possible_readers.except(recipients) else possible_readers end end |