Problem:
Private messaging in Rails.
Solution:
What it do?
acts_as_messageable is a plugin for enabling private messaging between users. Conversations, multiple recipients, trash, sentbox... its all in there.
to install:
> script/plugin install http://actsasmessageable.googlecode.com/svn/tags/acts_as_messageable-1.0.1 > script/generate messageable > rake db:migrate
to use:
class User < ActiveRecord::Base acts_as_messageable end
sending:
phil = User.find(3123) todd = User.find(4141) phil.send_message(todd, "whats up for tonight?", "hey guy")
sends a mail to todd's inbox and puts the sent message in phil's sentbox.
retrieving:
todd.mailbox[:inbox].unread_mail
returns an array of all unread mail messages in todd's inbox.
replying:
mail = todd.mailbox[:inbox].unread_mail[0] todd.reply_to_sender(mail, "not sure, probably having a few dozen cocktails.")
replys to the sender of the mail message. (Messages can be sent to multiple users, and are conversation based. See the RDoc.)
moving / deleting:
convo = mail.conversation todd.mailbox.move_to(:trash, :conversation => convo)
moves all mail messages to the 'trash' that are part of the given conversation. There are 3 default mailboxes for each user (:inbox, :sentbox, :trash), although any name can be passed to this method if you wanted to implement folders.
bonus:
todd.mailbox[:inbox].latest_mail
returns the last message received for each conversation you are involved in. Pretty sweet for an inbox view.
Check the RDoc.
