Class: Mailboxer::Message

Inherits:
Notification show all
Defined in:
app/models/mailboxer/message.rb

Instance Attribute Summary

Attributes inherited from Notification

#recipients

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Notification

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

Class Method Details

.on_deliver(callback_method) ⇒ Object

Sets the on deliver callback method.



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

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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/mailboxer/message.rb', line 25

def deliver(reply = false, should_clean = true)
  self.clean if should_clean

  #Receiver receipts
  temp_receipts = recipients.map { |r| build_receipt(r, 'inbox') }

  #Sender receipt
  sender_receipt = build_receipt(sender, 'sentbox', true)

  temp_receipts << sender_receipt

  if temp_receipts.all?(&:valid?)
    temp_receipts.each(&:save!)
    Mailboxer::MailDispatcher.new(self, recipients).call

    conversation.touch if reply

    self.recipients = nil

    on_deliver_callback.call(self) if on_deliver_callback
  end
  sender_receipt
end