Skip to content

Commit

Permalink
Enabled read/unread messages
Browse files Browse the repository at this point in the history
- Added setting messages as read on show action in messages_controller.rb
- Set unread messages as bold in messages _list.html.rb view
- Fixed bug in profile.rb model with has_many unread_messages relation
Fixed missing parantheses warning in forums_posts_controller.rb
  • Loading branch information
Tair committed Jul 31, 2008
1 parent 4199b37 commit c206361
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/controllers/forum_posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class ForumPostsController < ApplicationController
skip_filter :login_required, :only => [:show, :index]

def index
redirect_to forum_path @forum
redirect_to forum_path(@forum)
end
def show
redirect_to forum_path @forum
redirect_to forum_path(@forum)
end

def edit
Expand Down Expand Up @@ -88,4 +88,4 @@ def allow_to
super :user, :only => [:new, :create]
end

end
end
4 changes: 4 additions & 0 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def sent
def show
@message = @p.sent_messages.find params[:id] rescue nil
@message ||= @p.received_messages.find params[:id] rescue nil
if not @message.nil?
@message.read = true
@message.save
end
@to_list = [@message.sender]
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Profile < ActiveRecord::Base
# Messages
has_many :sent_messages, :class_name => 'Message', :order => 'created_at desc', :foreign_key => 'sender_id'
has_many :received_messages, :class_name => 'Message', :order => 'created_at desc', :foreign_key => 'receiver_id'
has_many :unread_messages, :class_name => 'Message', :conditions => ["read=?",false]
has_many :unread_messages, :class_name => 'Message', :conditions => {:read => false}, :foreign_key => 'receiver_id'

# Friends
has_many :friendships, :class_name => "Friend", :foreign_key => 'inviter_id', :conditions => "status = #{Friend::ACCEPTED}"
Expand Down
8 changes: 4 additions & 4 deletions app/views/messages/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ sent = params[:action]=='sent'
<% list.each do |m|
mail_user = (@p == m.sender ? m.receiver : m.sender)%>
<tr>
<td><%= link_to mail_user.f, mail_user %></td>
<td><%= time_ago_in_words m.created_at %></td>
<td><%= link_to h( m.subject), message_path(m) %></td>
<td <%= "class=\"unread\"" if !m.read %>><%= link_to mail_user.f, mail_user %></td>
<td <%= "class=\"unread\"" if !m.read %>><%= time_ago_in_words m.created_at %></td>
<td <%= "class=\"unread;\"" if !m.read %>><%= link_to h( m.subject), message_path(m) %></td>
</tr>
<% end %>
</table>
Expand All @@ -45,4 +45,4 @@ sent = params[:action]=='sent'

<div id="new_direct_message" class="hidden">
<%= render :partial => 'messages/form', :locals => {:hide_header => true} %>
</div>
</div>
3 changes: 2 additions & 1 deletion public/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ h2 a {text-transform: capitalize; font-weight: normal; font-size: 11px;}
#messages th {padding: 3px;}
#messages th {background: #971d4a; font-size: 10px;}
#messages {width: 100%;}
#messages .unread {font-weight: bold;}

.blurp {padding: 0 0 15px 0;}
.blurp strong {display: block; color: white;}
Expand Down Expand Up @@ -470,4 +471,4 @@ margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = d
margin-bottom:-1px;
margin-top:1px;
_margin-bottom:1px;
}
}

0 comments on commit c206361

Please sign in to comment.