message outbox
This commit is contained in:
parent
cdfc163e5f
commit
d736a158be
7 changed files with 74 additions and 4 deletions
|
@ -22,8 +22,8 @@ class MessageController < ApplicationController
|
|||
|
||||
def read
|
||||
@title = 'read message'
|
||||
@message = Message.find(params[:message_id], :conditions => ["to_user_id = ?", @user.id])
|
||||
@message.message_read = 1
|
||||
@message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
|
||||
@message.message_read = 1 if @message.to_user_id == @user.id
|
||||
@message.save
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :nothing => true, :status => :not_found
|
||||
|
@ -37,6 +37,14 @@ class MessageController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def outbox
|
||||
@title = 'outbox'
|
||||
if @user and params[:display_name] == @user.display_name
|
||||
else
|
||||
redirect_to :controller => 'message', :action => 'outbox', :display_name => @user.display_name
|
||||
end
|
||||
end
|
||||
|
||||
def mark
|
||||
if params[:message_id]
|
||||
id = params[:message_id]
|
||||
|
|
|
@ -5,6 +5,7 @@ class User < ActiveRecord::Base
|
|||
has_many :diary_entries, :order => 'created_at DESC'
|
||||
has_many :messages, :foreign_key => :to_user_id, :order => 'sent_on DESC'
|
||||
has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => "message_read = 0", :order => 'sent_on DESC'
|
||||
has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :order => 'sent_on DESC'
|
||||
has_many :friends
|
||||
has_many :tokens, :class_name => "UserToken"
|
||||
has_many :preferences, :class_name => "UserPreference"
|
||||
|
|
7
app/views/message/_sent_message_summary.rhtml
Normal file
7
app/views/message/_sent_message_summary.rhtml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<% this_colour = cycle('lightgrey', 'white') # can only call once for some dumb reason %>
|
||||
|
||||
<tr class="inbox-row<%= "-unread" if not sent_message_summary.message_read? %>">
|
||||
<td class="inbox-sender" bgcolor='<%= this_colour %>'><%= link_to sent_message_summary.recipient.display_name , :controller => 'user', :action => sent_message_summary.recipient.display_name %></td>
|
||||
<td class="inbox-subject" bgcolor='<%= this_colour %>'><%= link_to sent_message_summary.title , :controller => 'message', :action => 'read', :message_id => sent_message_summary.id %></td>
|
||||
<td class="inbox-sent" bgcolor='<%= this_colour %>'><%= sent_message_summary.sent_on %></td>
|
||||
</tr>
|
|
@ -1,4 +1,4 @@
|
|||
<h2>My inbox</h2>
|
||||
<h2>My inbox/<%= link_to "outbox", url_for(:controller => "user", :action => "outbox", :id => @user.display_name) %></h2>
|
||||
|
||||
<p>You have <%= @user.new_messages.size %> new messages and <%= @user.messages.size - @user.new_messages.size %> old messages</p>
|
||||
|
||||
|
@ -17,4 +17,4 @@
|
|||
</div>
|
||||
<% else %>
|
||||
<div id="messages">You have no messages yet. Why not get in touch with some of the <%= link_to 'people mapping nearby', :controller => 'user', :action => 'view', :display_name => @user.display_name %>?</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
18
app/views/message/outbox.rhtml
Normal file
18
app/views/message/outbox.rhtml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<h2>My <%= link_to "inbox", url_for(:controller => "user", :action => "inbox", :id => @user.display_name) %>/outbox</h2>
|
||||
|
||||
<p>You have <%= @user.sent_messages.size %> sent messages
|
||||
|
||||
<% if @user.sent_messages.size > 0 %>
|
||||
<div id="messages">
|
||||
<table class="messages">
|
||||
<tr>
|
||||
<th>To</th>
|
||||
<th>Subject</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
<%= render :partial => "sent_message_summary", :collection => @user.sent_messages %>
|
||||
</table>
|
||||
</div>
|
||||
<% else %>
|
||||
<div id="messages">You have no sent messages yet. Why not get in touch with some of the <%= link_to 'people mapping nearby', :controller => 'user', :action => 'view', :display_name => @user.display_name %>?</div>
|
||||
<% end %>
|
|
@ -1,3 +1,5 @@
|
|||
<% if @user == @message.recipient %>
|
||||
|
||||
<h2>Reading your messages</h2>
|
||||
|
||||
<table>
|
||||
|
@ -28,3 +30,36 @@
|
|||
<td><%= link_to 'Back to inbox', :controller => 'message', :action => 'inbox', :display_name => @user.display_name %></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<% else %>
|
||||
|
||||
<h2>Reading your sent messages</h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th align="right">To</th>
|
||||
<td><%= link_to @message.recipient.display_name, :controller => 'user', :action => 'view', :display_name => @message.recipient.display_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="right">Subject</th>
|
||||
<td><%= @message.title %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="right">Date</th>
|
||||
<td><%= @message.sent_on %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td><%= @message.body %></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><%= link_to 'Back to outbox', :controller => 'message', :action => 'outbox', :display_name => @user.display_name %></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<% end %>
|
||||
|
|
|
@ -118,6 +118,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
# messages
|
||||
|
||||
map.connect '/user/:display_name/inbox', :controller => 'message', :action => 'inbox'
|
||||
map.connect '/user/:display_name/outbox', :controller => 'message', :action => 'outbox'
|
||||
map.connect '/message/new/:user_id', :controller => 'message', :action => 'new'
|
||||
map.connect '/message/read/:message_id', :controller => 'message', :action => 'read'
|
||||
map.connect '/message/mark/:message_id', :controller => 'message', :action => 'mark'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue