Class: Message

Inherits:
Notification show all
Includes:
Concerns::ConfigurableMailer
Defined in:
app/models/message.rb

Instance Attribute Summary

Attributes inherited from Notification

#recipients

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::ConfigurableMailer

#get_mailer

Methods inherited from Notification

#clean, #expire, #expire!, #expired?, #is_read?, #is_trashed?, #is_unread?, #mark_as_read, #mark_as_unread, #move_to_trash, notify_all, #object, #receipt_for, #receipts_for, successful_delivery?, #untrash

Class Method Details

.on_deliver(callback_method) ⇒ Object

Sets the on deliver callback method.



19
20
21
# File 'app/models/message.rb', line 19

def on_deliver(callback_method)
  self.on_deliver_callback = callback_method
end

Instance Method Details

#deliver(reply = false, should_clean = true) ⇒ Object

Delivers a Message. USE NOT RECOMENDED. Use Mailboxer::Models::Message.send_message instead.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/message.rb', line 26

def deliver(reply = false, 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.is_read = false
    msg_receipt.receiver = r
    msg_receipt.mailbox_type = "inbox"
    temp_receipts << msg_receipt
  end
  #Sender receipt
  sender_receipt = Receipt.new
  sender_receipt.notification = self
  sender_receipt.is_read = true
  sender_receipt.receiver = self.sender
  sender_receipt.mailbox_type = "sentbox"
  temp_receipts << sender_receipt

  temp_receipts.each(&:valid?)
  if temp_receipts.all? { |t| t.errors.empty? }
    temp_receipts.each(&:save!) 	#Save receipts
    self.recipients.each do |r|
    #Should send an email?
      if Mailboxer.uses_emails
        email_to = r.send(Mailboxer.email_method,self)
        unless email_to.blank?
          get_mailer.send_email(self,r).deliver
        end
      end
    end
    if reply
      self.conversation.touch
    end
    self.recipients=nil
  self.on_deliver_callback.call(self) unless self.on_deliver_callback.nil?
  end
  return sender_receipt
end