Module: Mailboxer::Models::Messageable::InstanceMethods
- Defined in:
- lib/mailboxer/models/messageable.rb
Instance Method Summary collapse
-
#mailbox ⇒ Object
Gets the mailbox of the messageable.
-
#notify(subject, body) ⇒ Object
Sends a notification to the messageable.
-
#read(obj) ⇒ Object
Mark the object as read for messageable.
-
#reply(conversation, recipients, reply_body, subject = nil) ⇒ Object
Basic reply method.
-
#reply_to_all(receipt, reply_body, subject = nil) ⇒ Object
Replies to all the recipients of the message in the conversation.
-
#reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true) ⇒ Object
Replies to all the recipients of the last message in the conversation and untrash any trashed message by messageable if should_untrash is set to true (this is so by default).
-
#reply_to_sender(receipt, reply_body, subject = nil) ⇒ Object
Replies to the sender of the message in the conversation.
-
#send_message(recipients, msg_body, subject) ⇒ Object
Sends a messages, starting a new conversation, with the messageable as originator.
-
#unread(obj) ⇒ Object
Mark the object as unread for messageable.
Instance Method Details
#mailbox ⇒ Object
Gets the mailbox of the messageable
49 50 51 52 53 |
# File 'lib/mailboxer/models/messageable.rb', line 49 def mailbox @mailbox = Mailbox.new(self) if @mailbox.nil? @mailbox.type = :all return @mailbox end |
#notify(subject, body) ⇒ Object
Sends a notification to the messageable
56 57 58 59 60 |
# File 'lib/mailboxer/models/messageable.rb', line 56 def notify(subject,body) notification = Notification.new({:body => body, :subject => subject}) notification.recipients = [self] return notification.deliver end |
#read(obj) ⇒ Object
Mark the object as read for messageable.
Object can be:
-
A Receipt
-
A Message
-
A Notification
-
A Conversation
-
An array with any of them
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/mailboxer/models/messageable.rb', line 111 def read(obj) case obj when Receipt return obj.mark_as_read if obj.receiver == self when Message, Notification receipt = obj.receipt_for(self) return receipt.mark_as_read when Conversation receipts = obj.receipts_for(self) return receipts.mark_as_read when Array obj.map{ |sub_obj| read(sub_obj) } else return nil end end |
#reply(conversation, recipients, reply_body, subject = nil) ⇒ Object
Basic reply method. USE NOT RECOMENDED. Use reply_to_sender, reply_to_all and reply_to_conversation instead.
74 75 76 77 78 79 80 81 |
# File 'lib/mailboxer/models/messageable.rb', line 74 def reply(conversation, recipients, reply_body, subject = nil) subject = subject || "RE: #{conversation.subject}" response = Message.new({:sender => self, :conversation => conversation, :body => reply_body, :subject => subject}) response.recipients = recipients.is_a?(Array) ? recipients : [recipients] response.recipients = response.recipients.uniq response.recipients.delete(self) return response.deliver(true) end |
#reply_to_all(receipt, reply_body, subject = nil) ⇒ Object
Replies to all the recipients of the message in the conversation
89 90 91 |
# File 'lib/mailboxer/models/messageable.rb', line 89 def reply_to_all(receipt, reply_body, subject = nil) return reply(receipt.conversation, receipt..recipients, reply_body, subject) end |
#reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true) ⇒ Object
Replies to all the recipients of the last message in the conversation and untrash any trashed message by messageable if should_untrash is set to true (this is so by default)
95 96 97 98 99 100 101 |
# File 'lib/mailboxer/models/messageable.rb', line 95 def reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true) #move conversation to inbox if it is currently in the trash and should_untrash parameter is true. if should_untrash && mailbox.is_trashed?(conversation) mailbox.receipts_for(conversation).untrash end return reply(conversation, conversation..recipients, reply_body, subject) end |
#reply_to_sender(receipt, reply_body, subject = nil) ⇒ Object
Replies to the sender of the message in the conversation
84 85 86 |
# File 'lib/mailboxer/models/messageable.rb', line 84 def reply_to_sender(receipt, reply_body, subject = nil) return reply(receipt.conversation, receipt..sender, reply_body, subject) end |
#send_message(recipients, msg_body, subject) ⇒ Object
Sends a messages, starting a new conversation, with the messageable as originator
64 65 66 67 68 69 70 |
# File 'lib/mailboxer/models/messageable.rb', line 64 def (recipients, msg_body, subject) convo = Conversation.new({:subject => subject}) = Message.new({:sender => self, :conversation => convo, :body => msg_body, :subject => subject}) .recipients = recipients.is_a?(Array) ? recipients : [recipients] .recipients = .recipients.uniq return .deliver end |
#unread(obj) ⇒ Object
Mark the object as unread for messageable.
Object can be:
-
A Receipt
-
A Message
-
A Notification
-
A Conversation
-
An array with any of them
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/mailboxer/models/messageable.rb', line 136 def unread(obj) case obj when Receipt return obj.mark_as_unread if obj.receiver == self when Message, Notification receipt = obj.receipt_for(self) return receipt.mark_as_unread when Conversation receipts = obj.receipts_for(self) return receipts.mark_as_unread when Array obj.map{ |sub_obj| unread(sub_obj) } else return nil end end |