Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added reply functionality

  • Loading branch information...
commit 86ef5146a961783c6a5820e40a3e16286216a3f3 1 parent c98e044
@davidchua davidchua authored
View
13 README.rdoc
@@ -105,6 +105,19 @@ to delete the message
# 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:
View
10 about.yml
@@ -1,8 +1,10 @@
-author: Nugroho Herucahyono
+author: David Chua
summary: add a nice and simple internal messaging system between users in your application.
description: "Hmmph... yeah, like the little inbox in your facebook, maybe..."
-homepage: http://github.com/xinuc/has_messages
-plugin: git://github.com/xinuc/has_messages.git
+homepage: http://github.com/davidchua/has_messages
+plugin: git://github.com/davidchua/has_messages.git
license: MIT
-version: 0.01
+version: 0.03
rails_version: 2.0+
+
+forked from: http://github.com/xinuc/has_messages
View
2  generators/has_messages/templates/migration.rb
@@ -14,6 +14,8 @@ def self.up
t.string :receiver_type
t.integer :receiver_id
+ t.integer :reply_of
+
t.boolean :trashed_by_sender, :default => false
t.boolean :trashed_by_receiver, :default => false
View
13 lib/has_messages.rb
@@ -39,12 +39,23 @@ def send_message(receiver, subject, body)
@message = Message.new(:receiver => receiver, :sender => self, :subject => subject,
:body => body)
@message.save
- @message.deliver_message_notification!
+ @message.deliver_message_notification! if (defined?(Notifier) and Notifier.responds_to?(message_notification))
+ end
+
+ def reply_message(message, subject, body)
+ @message = Message.new(:receiver => message.sender, :sender => self, :subject => subject, :body => body, :reply_of => message.id)
+ @message.save
+ @message.deliver_message_notification! if (defined?(Notifier) and Notifier.responds_to?(message_notification))
end
def delete_message(message_id)
Message.trash_message self, message_id
end
+
+ def get_replies(message_id)
+ # test if current user is a sender/receiver of message_id else fails
+ Message.find(:all, :conditions => {:reply_of => message_id})
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.