Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
fix message test
Browse files Browse the repository at this point in the history
  • Loading branch information
bborn committed Feb 12, 2011
1 parent 30c5139 commit fc5978a
Show file tree
Hide file tree
Showing 34 changed files with 74 additions and 737 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ LONG VERSION:
7. Modify each environment file (`development.rb`, `test.rb`, and `production.rb`) as indicated below:

# development.rb, production.rb, and test.rb should include something like:
APP_URL = "http://localhost:3000" (or whatever your URL will be for that particular environment)
configatron.app_host = "http://localhost:3000" (or whatever your URL will be for that particular environment)

8. Modify your routes.rb as indicated below:

Expand Down
53 changes: 41 additions & 12 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
class Message < ActiveRecord::Base
is_private_message

class Message < ActiveRecord::Base
attr_accessor :to
attr_accessor :reply_to

belongs_to :parent, :class_name => "Message", :foreign_key => "parent_id"
has_many :children, :class_name => "Message", :foreign_key => "parent_id"
has_many :message_threads

scope :parents, where("parent_id IS NULL")
belongs_to :sender, :class_name => 'User', :foreign_key => 'sender_id', :inverse_of => :sent_messages
belongs_to :recipient, :class_name => 'User', :foreign_key => 'recipient_id', :inverse_of => :received_messages

belongs_to :parent, :class_name => "Message", :foreign_key => "parent_id", :inverse_of => :children
has_many :children, :class_name => "Message", :foreign_key => "parent_id", :inverse_of => :parent
has_many :message_threads

scope :parent_messages, where("parent_id IS NULL")
scope :already_read, where("read_at IS NOT NULL")
scope :unread, where("read_at IS NULL")

validates_presence_of :body, :subject
validates_presence_of :recipient, :message => "is invalid"
validate :ensure_not_sending_to_self

after_create :notify_recipient
after_create :update_message_threads


# Ensures the passed user is either the sender or the recipient then returns the message.
# If the reader is the recipient and the message has yet not been read, it marks the read_at timestamp.
def self.read(id, reader)
message = find(id, :conditions => ["sender_id = ? OR recipient_id = ?", reader, reader])
if message.read_at.nil? && reader == message.recipient
message.read_at = Time.now
message.save!
end
message
end

# Returns true or false value based on whether the a message has been read by it's recipient.
def read?
self.read_at.nil? ? false : true
end

# Marks a message as deleted by either the sender or the recipient, which ever the user that was passed is.
# Once both have marked it deleted, it is destroyed.
def mark_deleted(user)
self.sender_deleted = true if self.sender == user
self.recipient_deleted = true if self.recipient == user
self.sender_deleted && self.recipient_deleted ? self.destroy : save!
end


def ensure_not_sending_to_self
errors.add_to_base("You may not send a message to yourself.") if self.recipient && self.recipient.eql?(self.sender)
errors.add(:base, "You may not send a message to yourself.") if self.recipient && self.recipient.eql?(self.sender)
end

def notify_recipient
Expand All @@ -40,15 +69,15 @@ def update_message_threads
def self.new_reply(sender, message_thread = nil, params = {})
message = new(params[:message])
message.to ||= params[:to] if params[:to]

if message_thread
message.parent = message_thread.parent_message
message.reply_to = message_thread.message
message.to = message_thread.sender.login
message.subject = message_thread.parent_message.subject
message.sender = sender
end

message
end

Expand Down
26 changes: 25 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class User < ActiveRecord::Base

acts_as_taggable
acts_as_commentable
has_private_messages
tracks_unlinked_activities [:logged_in, :invited_friends, :updated_profile, :joined_the_site]

#callbacks
Expand Down Expand Up @@ -75,6 +74,20 @@ class User < ActiveRecord::Base
has_many :clippings, :order => "created_at desc", :dependent => :destroy
has_many :favorites, :order => "created_at desc", :dependent => :destroy

#messages
has_many :all_sent_messages, :class_name => "Message", :foreign_key => "sender_id", :dependent => :destroy
has_many :sent_messages,
:class_name => 'Message',
:foreign_key => 'sender_id',
:order => "messages.created_at DESC",
:conditions => ["messages.sender_deleted = ?", false]

has_many :received_messages,
:class_name => 'Message',
:foreign_key => 'recipient_id',
:order => "message.created_at DESC",
:conditions => ["message.recipient_deleted = ?", false]

#named scopes
scope :recent, order('users.created_at DESC')
scope :featured, where("users.featured_writer = ?", true)
Expand Down Expand Up @@ -434,6 +447,17 @@ def update_last_seen_at
self.sb_last_seen_at = Time.now.utc
end

def unread_messages?
unread_message_count > 0 ? true : false
end

# Returns the number of unread messages for this user
def unread_message_count
Message.count(:conditions => ["recipient_id = ? AND read_at IS NULL", self])
end



## End Instance Methods


Expand Down
2 changes: 1 addition & 1 deletion app/views/user_notifier/follow_up_comment_notice.fr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ L'Equipe <%= configatron.community_name %>
---------------------------------------------------------------------------------
Si vous ne souhaitez plus recevoir d'email comme celui-ci de la part de <%= configatron.community_name %>, vous pouvez modifier vos préférences :

<%= APP_URL %>/<%= @user.login_slug %>/edit_account
<%= configatron.app_host %>/<%= @user.login_slug %>/edit_account
2 changes: 1 addition & 1 deletion app/views/user_notifier/message_notification.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ The <%= configatron.community_name %> team

Forgot your <%= configatron.community_name %> password? Visit this URL to reset it:

<%= APP_URL %>/forgot_password
<%= configatron.app_host %>/forgot_password
2 changes: 1 addition & 1 deletion app/views/user_notifier/new_forum_post_notice.fr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ L'Equipe <%= configatron.community_name %>
---------------------------------------------------------------------------------
Si vous ne souhaitez plus recevoir d'email comme celui-ci de <%= configatron.community_name %>, Vous pouvez modifier vos préférences :

<%= APP_URL %>/<%= @user.login_slug %>/edit_account
<%= configatron.app_host %>/<%= @user.login_slug %>/edit_account
6 changes: 3 additions & 3 deletions community_engine_setup_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def modify_environment_files

say "Modifying environment files ..."
['development', 'test'].each do |env|
environment "\nAPP_URL = \"http://localhost:3000\"", :env => env
environment "\nconfigatron.app_host = \"http://localhost:3000\"", :env => env
end
app_url = ask("Please enter the url where you plan to deploy this app (use 'example.com' for now if you don't know yet):")
environment "\nAPP_URL = \"http://#{app_url}\"", :env => 'production'
configatron.app_host = ask("Please enter the url where you plan to deploy this app (use 'example.com' for now if you don't know yet):")
environment "\nconfigatron.app_host = \"http://#{configatron.app_host}\"", :env => 'production'
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/rakismet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# if configatron.akismet_key
# app.config.raksmet.key = configatron.akismet_key
# app.config.raksmet.url = APP_URL.gsub("http://", '')
# app.config.raksmet.url = configatron.app_host.gsub("http://", '')
# end
#
# end
20 changes: 0 additions & 20 deletions vendor/plugins/simple_private_messages/MIT-LICENSE

This file was deleted.

139 changes: 0 additions & 139 deletions vendor/plugins/simple_private_messages/README

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/plugins/simple_private_messages/Rakefile

This file was deleted.

This file was deleted.

Loading

0 comments on commit fc5978a

Please sign in to comment.