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, obj = nil, sanitize_text = true, notification_code = nil) ⇒ Object
Sends a notification to the messageable.
-
#read(obj) ⇒ Object
Mark the object as read for messageable.
-
#reply(conversation, recipients, reply_body, subject = nil, sanitize_text = true, attachment = nil) ⇒ Object
Basic reply method.
-
#reply_to_all(receipt, reply_body, subject = nil, sanitize_text = true, attachment = nil) ⇒ Object
Replies to all the recipients of the message in the conversation.
-
#reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true, sanitize_text = true, attachment = nil) ⇒ 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, sanitize_text = true, attachment = nil) ⇒ Object
Replies to the sender of the message in the conversation.
- #search_messages(query) ⇒ Object
-
#send_message(recipients, msg_body, subject, sanitize_text = true, attachment = nil) ⇒ Object
Sends a messages, starting a new conversation, with the messageable as originator.
-
#trash(obj) ⇒ Object
Mark the object as trashed for messageable.
-
#unread(obj) ⇒ Object
Mark the object as unread for messageable.
-
#untrash(obj) ⇒ Object
Mark the object as not trashed for messageable.
Instance Method Details
#mailbox ⇒ Object
Gets the mailbox of the messageable
37 38 39 40 41 |
# File 'lib/mailboxer/models/messageable.rb', line 37 def mailbox @mailbox = Mailbox.new(self) if @mailbox.nil? @mailbox.type = :all return @mailbox end |
#notify(subject, body, obj = nil, sanitize_text = true, notification_code = nil) ⇒ Object
Sends a notification to the messageable
44 45 46 |
# File 'lib/mailboxer/models/messageable.rb', line 44 def notify(subject,body,obj = nil,sanitize_text=true,notification_code=nil) return Notification.notify_all([self],subject,body,obj,sanitize_text,notification_code) 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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mailboxer/models/messageable.rb', line 97 def read(obj) case obj when Receipt return obj.mark_as_read if obj.receiver == self when Message, Notification obj.mark_as_read(self) when Conversation obj.mark_as_read(self) when Array obj.map{ |sub_obj| read(sub_obj) } else return nil end end |
#reply(conversation, recipients, reply_body, subject = nil, sanitize_text = true, attachment = nil) ⇒ Object
Basic reply method. USE NOT RECOMENDED. Use reply_to_sender, reply_to_all and reply_to_conversation instead.
60 61 62 63 64 65 66 67 |
# File 'lib/mailboxer/models/messageable.rb', line 60 def reply(conversation, recipients, reply_body, subject=nil, sanitize_text=true, =nil) subject = subject || "RE: #{conversation.subject}" response = Message.new({:sender => self, :conversation => conversation, :body => reply_body, :subject => subject, :attachment => }) response.recipients = recipients.is_a?(Array) ? recipients : [recipients] response.recipients = response.recipients.uniq response.recipients.delete(self) return response.deliver true, sanitize_text end |
#reply_to_all(receipt, reply_body, subject = nil, sanitize_text = true, attachment = nil) ⇒ Object
Replies to all the recipients of the message in the conversation
75 76 77 |
# File 'lib/mailboxer/models/messageable.rb', line 75 def reply_to_all(receipt, reply_body, subject=nil, sanitize_text=true, =nil) return reply(receipt.conversation, receipt..recipients, reply_body, subject, sanitize_text, ) end |
#reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true, sanitize_text = true, attachment = nil) ⇒ 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)
81 82 83 84 85 86 87 |
# File 'lib/mailboxer/models/messageable.rb', line 81 def reply_to_conversation(conversation, reply_body, subject=nil, should_untrash=true, sanitize_text=true, =nil) #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, sanitize_text, ) end |
#reply_to_sender(receipt, reply_body, subject = nil, sanitize_text = true, attachment = nil) ⇒ Object
Replies to the sender of the message in the conversation
70 71 72 |
# File 'lib/mailboxer/models/messageable.rb', line 70 def reply_to_sender(receipt, reply_body, subject=nil, sanitize_text=true, =nil) return reply(receipt.conversation, receipt..sender, reply_body, subject, sanitize_text, ) end |
#search_messages(query) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/mailboxer/models/messageable.rb', line 181 def (query) @search = Receipt.search do fulltext query with :receiver_id, self.id end @search.results.map { |r| r.conversation }.uniq end |
#send_message(recipients, msg_body, subject, sanitize_text = true, attachment = nil) ⇒ Object
Sends a messages, starting a new conversation, with the messageable as originator
50 51 52 53 54 55 56 |
# File 'lib/mailboxer/models/messageable.rb', line 50 def (recipients, msg_body, subject, sanitize_text=true, =nil) convo = Conversation.new({:subject => subject}) = Message.new({:sender => self, :conversation => convo, :body => msg_body, :subject => subject, :attachment => }) .recipients = recipients.is_a?(Array) ? recipients : [recipients] .recipients = .recipients.uniq return .deliver false,sanitize_text end |
#trash(obj) ⇒ Object
Mark the object as trashed for messageable.
Object can be:
-
A Receipt
-
A Message
-
A Notification
-
A Conversation
-
An array with any of them
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/mailboxer/models/messageable.rb', line 143 def trash(obj) case obj when Receipt return obj.move_to_trash if obj.receiver == self when Message, Notification obj.move_to_trash(self) when Conversation obj.move_to_trash(self) when Array obj.map{ |sub_obj| trash(sub_obj) } else return nil end 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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/mailboxer/models/messageable.rb', line 120 def unread(obj) case obj when Receipt return obj.mark_as_unread if obj.receiver == self when Message, Notification obj.mark_as_unread(self) when Conversation obj.mark_as_unread(self) when Array obj.map{ |sub_obj| unread(sub_obj) } else return nil end end |
#untrash(obj) ⇒ Object
Mark the object as not trashed for messageable.
Object can be:
-
A Receipt
-
A Message
-
A Notification
-
A Conversation
-
An array with any of them
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/mailboxer/models/messageable.rb', line 166 def untrash(obj) case obj when Receipt return obj.untrash if obj.receiver == self when Message, Notification obj.untrash(self) when Conversation obj.untrash(self) when Array obj.map{ |sub_obj| untrash(sub_obj) } else return nil end end |