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
48
# File 'app/models/mailboxer/message.rb', line 25

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

  #Receiver receipts
  receiver_receipts = recipients.map do |r|
    receipts.build(receiver: r, mailbox_type: 'inbox', is_read: false)
  end

  #Sender receipt
  sender_receipt =
    receipts.build(receiver: sender, mailbox_type: 'sentbox', is_read: true)

  if valid?
    save!
    Mailboxer::MailDispatcher.new(self, receiver_receipts).call

    conversation.touch if reply

    self.recipients = nil

    on_deliver_callback.call(self) if on_deliver_callback
  end
  sender_receipt
end