app/models/messageable.rb in mailboxer_multi_attach-0.0.3 vs app/models/messageable.rb in mailboxer_multi_attach-0.0.4
- old
+ new
@@ -1,21 +1,44 @@
module Mailboxer
module Models
module Messageable # :nodoc:
+ included do
+ class Mailboxer::Message
+ has_many :message_attachments
+ attr_accessible :message_attachments
+ end
+ end
+
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 reply(conversation, recipients, reply_body,
+ subject=nil, sanitize_text=true,
+ attachment=nil)
+ subject = subject || "#{conversation.subject}"
+ build_message(conversation, recipients,
+ reply_body, subject,
+ message_timestamp = Time.now)
+ end
+
+ def reply_to_sender_mult_attach(receipt, reply_body,
+ subject = nil, sanitize_text = true,
+ attachments = nil)
+ message = reply(receipt.conversation, receipt.message.sender, reply_body, subject, sanitize_text)
+ attach_files(attachments, message)
+ message.deliver false, sanitize_text
+ end
+
def build_convo(subject, message_timestamp)
::Mailboxer::ConversationBuilder.new(
subject: subject,
created_at: message_timestamp,
updated_at: message_timestamp
@@ -32,18 +55,11 @@
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
- end
-
def attach_files(attachments, message)
- return unless attachments.present?
+ return if attachments.blank?
attachments.each do |m|
message.message_attachments << MessageAttachment.new(file: m[:file])
end
end
end