Module: Photon::Delivers::Core::InstanceMethods
- Defined in:
- lib/photon/delivers/core.rb
Instance Method Summary collapse
- #read(message) ⇒ Object
- #read_messages ⇒ Object
- #reply_to(message, opts = {}) ⇒ Object
- #send_message(opts = {}) ⇒ Object
- #sent_messages ⇒ Object
- #unread(message) ⇒ Object
- #unread_count ⇒ Object
- #unread_messages ⇒ Object
Instance Method Details
#read(message) ⇒ Object
43 44 45 |
# File 'lib/photon/delivers/core.rb', line 43 def read() change_read_status(, true) end |
#read_messages ⇒ Object
38 39 40 41 |
# File 'lib/photon/delivers/core.rb', line 38 def through_string = Photon.through.to_s constantize_model(Photon.using).where("#{through_string}.#{self.class.to_s.downcase}_id = ? AND #{through_string}.read IS ?", self.id, true).joins(Photon.through) end |
#reply_to(message, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/photon/delivers/core.rb', line 51 def reply_to(, opts = {}) if .nil? || opts[:body].nil? || opts[:subject].nil? false else delivery_object = constantize_model(Photon.through).where("#{self.class.to_s.downcase}_id = ? AND #{Photon.using.to_s.singularize}_id = ?", self.id, .id).first self.(:to => .sender, :message_thread_id => delivery_object., :subject => opts[:subject], :body => opts[:body]) end end |
#send_message(opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/photon/delivers/core.rb', line 13 def (opts={}) if opts[:to].nil? || opts[:subject].nil? || opts[:body].nil? false else opts[:message_thread_id] = opts[:message_thread_id] || constantize_model(Photon.thread).create.id = constantize_model(Photon.using).create!(:sender => self, :users => [opts[:to]].flatten, :subject => opts[:subject], :body => opts[:body] ) .deliveries.update_all({:message_thread_id => opts[:message_thread_id], :scope_id => opts[:scope_id], :scope_type => opts[:scope_type]}) return end end |
#sent_messages ⇒ Object
29 30 31 |
# File 'lib/photon/delivers/core.rb', line 29 def constantize_model(Photon.using).where(:sender_id => self.id) end |
#unread(message) ⇒ Object
47 48 49 |
# File 'lib/photon/delivers/core.rb', line 47 def unread() change_read_status(, false) end |
#unread_count ⇒ Object
60 61 62 63 |
# File 'lib/photon/delivers/core.rb', line 60 def unread_count through_string = Photon.through.to_s constantize_model(Photon.using).where("#{through_string}.#{self.class.to_s.downcase}_id = ? AND #{through_string}.read IS NOT ?", self.id, true).joins(Photon.through).count end |
#unread_messages ⇒ Object
33 34 35 36 |
# File 'lib/photon/delivers/core.rb', line 33 def through_string = Photon.through.to_s constantize_model(Photon.using).where("#{through_string}.#{self.class.to_s.downcase}_id = ? AND #{through_string}.read IS NOT ?", self.id, true).joins(Photon.through) end |