github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

davidchua / has_messages forked from xinuc/has_messages

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 2
  • Source
  • Commits
  • Network (2)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

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

  cancel

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

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added reply functionality 
davidchua (author)
Tue Oct 20 12:50:23 -0700 2009
commit  86ef5146a961783c6a5820e40a3e16286216a3f3
tree    e594b54d8695805d970d9f7c74ec39f9548f1e72
parent  c98e0441e436fd1ffb62c26e2f76e76556505369
has_messages /
name age
history
message
file .gitignore Loading commit data...
file MIT-LICENSE Thu May 14 23:53:27 -0700 2009 hopefully already usable [xinuc]
file README.rdoc Tue Oct 20 12:50:23 -0700 2009 Added reply functionality [davidchua]
file Rakefile Thu May 14 23:53:27 -0700 2009 hopefully already usable [xinuc]
file about.yml Tue Oct 20 12:50:23 -0700 2009 Added reply functionality [davidchua]
directory generators/ Tue Oct 20 12:50:23 -0700 2009 Added reply functionality [davidchua]
file init.rb Thu May 14 23:53:27 -0700 2009 hopefully already usable [xinuc]
file install.rb Thu May 14 23:53:27 -0700 2009 hopefully already usable [xinuc]
directory lib/
directory tasks/ Thu May 14 23:53:27 -0700 2009 hopefully already usable [xinuc]
file uninstall.rb Thu May 14 23:53:27 -0700 2009 hopefully already usable [xinuc]
README.rdoc

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

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server