app/models/messageable.rb in mailboxer_multi_attach-0.0.2 vs app/models/messageable.rb in mailboxer_multi_attach-0.0.3
- old
+ new
@@ -1,59 +1,52 @@
module Mailboxer
module Models
- module Messageable
+ module Messageable # :nodoc:
+ def send_message_mult_attach(recipients, msg_body,
+ subject, sanitize_text = true,
+ attachments = nil,
+ message_timestamp = Time.now)
+ convo = build_convo(subject, message_timestamp)
+ message = build_message(convo, recipients,
+ msg_body, subject,
+ message_timestamp)
+ connect_message_to_message_attachments
+ attach_files(attachments, message)
+ message.deliver false, sanitize_text
+ end
- def send_message_mult_attach(recipients, msg_body, subject, sanitize_text=true, attachments=nil, message_timestamp = Time.now)
- convo = ::Mailboxer::ConversationBuilder.new({
- :subject => subject,
- :created_at => message_timestamp,
- :updated_at => message_timestamp
- }).build
+ def build_convo(subject, message_timestamp)
+ ::Mailboxer::ConversationBuilder.new(
+ subject: subject,
+ created_at: message_timestamp,
+ updated_at: message_timestamp
+ ).build
+ end
- message = ::Mailboxer::MessageBuilder.new({
- :sender => self,
- :conversation => convo,
- :recipients => recipients,
- :body => msg_body,
- :subject => subject,
- :created_at => message_timestamp,
- :updated_at => message_timestamp
- }).build
+ def build_message(convo, recipients, msg_body, subject, message_timestamp)
+ ::Mailboxer::MessageBuilder.new(
+ sender: self,
+ conversation: convo,
+ recipients: recipients,
+ body: msg_body,
+ subject: subject,
+ created_at: message_timestamp,
+ updated_at: message_timestamp
+ ).build
+ end
+ def connect_message_to_message_attachments
Mailboxer::Message.class_eval do
has_many :message_attachments
attr_accessible :message_attachments
end
-
- if attachments.present?
- attachments.each do |m|
- message.message_attachments << MessageAttachment.new(file: m[:file])
- end
- end
- message.deliver false, sanitize_text
end
- def reply_to_convo_mult_attach(convo, convo_body, subject, sanitize_text=true, attachment=nil)
- if should_untrash && mailbox.is_trashed?(conversation)
- mailbox.receipts_for(conversation).untrash
- mailbox.receipts_for(conversation).mark_as_not_deleted
+ def attach_files(attachments, message)
+ return unless attachments.present?
+ attachments.each do |m|
+ message.message_attachments << MessageAttachment.new(file: m[:file])
end
- reply_mult_attach(conversation, conversation.last_message.recipients, reply_body, subject, sanitize_text, attachment)
- end
-
- def reply_mult_attach(conversation, recipients, reply_body, subject=nil, sanitize_text=true, attachment=nil)
- subject ||= "#{conversation.subject}"
- response = Mailboxer::MessageBuilder.new({
- :sender => self,
- :conversation => recipients,
- :body => reply_body,
- :subject => subject
- }).build
-
- #TODO: handle attachments
-
- response.recipients.delete(self)
- response.deliver true, sanitize_text
end
end
end
end