Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.
/ has_messages Public archive

This plugin provides a nice and easy way to create simple internal messaging system in your application.

License

Notifications You must be signed in to change notification settings

xinuc/has_messages

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mike Gunderloyxinuc
Mike Gunderloy
and
May 3, 2010
477f8fa · May 3, 2010

History

11 Commits
Oct 20, 2009
May 3, 2010
May 15, 2009
Oct 29, 2009
May 15, 2009
Oct 20, 2009
May 15, 2009
Oct 20, 2009
May 15, 2009
May 15, 2009
May 15, 2009

Repository files navigation

HasMessages

This plugin provides a nice and easy way to create simple internal messaging system in your application.

This is a fork of xinuc’s has_messages, which adds e-mail notification support.

implementation

Usage

These instructions will show you how to use the plugin.

Generator

Run the generator from your RAILS_ROOT:

./script/generate has_messages

This will create:

Model:      RAILS_ROOT/app/models/message.rb
Migration:  RAILS_ROOT/db/migrate/xxx_create_messages.rb

If you would like to add e-mail notification support so that users will receive an e-mail upon a new message entering their mailbox, use the following instead:

./script/generate has_messages --email

This will create the necessary models for email notification.

Database

And you will need to run a database migration from your RAILS_ROOT:

rake db:migrate

Email Notification

Other than running ./script/generate has_messages –email

All you need to do is to make sure your ActionMailer configuration is added to your environment

Remember to edit the template of the email at app/views/notifier/message_notification.html.erb to take into account the attributes of your User model

Mixin

add has_messages to your user-like model:

class User < ActiveRecord::Base
  has_messages
  ...
end

or yes, just any activerecord models:

class Company < ActiveRecord::Base
  has_messages
  ...
end

Read and send messages

To get the messages:

user = User.find some_id
user.inbox # will return all messages received by the user
user.outbox # will return all messages sent by the user

user.has_new_messages? # return true if the user has unread messages
user.new_messages # return all unread messages

and you can add options to the methods, like:

user.inbox :limit => 20 # will return last 20 received messages

to read the message:

message = user.read_message(message_id)
# receive a message_id (generally from the request's params) and return the message object
# this method will set the message as read

subject = message.subject
sender = message.sender
body = message.body # return the body of the message (string)
sent_at = message.sent_at

to send a message:

me = User.find some_id
delilah = User.find some_other_id

subject = "Hi there Delilah"
body = "What's it like in New York city??"

me.send_message(delilah, subject, body) # send_message(receiver, subject, body)

to delete the message

user.delete_message(message_id)
# receive a message_id and set the message as trashed,
# delete the record if the message has been trashed by both sender and receiver.
# don't use <tt>message.destroy</tt> directly, cause it will delete the message
# both from the receiver's inbox and sender's outbox. The users will be confused :-(

Reply Messages

To reply to a message

message = Message.find some_id

user = User.find some_id
user.reply_message(message, subject, body)

To get all replies belonging to a message

user = User.find some_id
user.get_replies(message_id)

Installation

Run the following command in your RAILS_ROOT:

./script/plugin install git://github.com/davidchua/has_messages.git

Or, simply get the tarball at:

http://github.com/davidchua/has_messages/tarball/master

extract it to your vendor/plugins and rename it to ‘has_messages’

Bugs, Patches or Feature requests

If you find any bugs, submit your patches or request any features, drop me an email: zhchua@gmail.com

About

This plugin provides a nice and easy way to create simple internal messaging system in your application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages