add support for viewing sent private messages
This commit is contained in:
parent
08a8165fa9
commit
464b3c3f80
|
@ -8,11 +8,26 @@ class MessagesController < ApplicationController
|
||||||
|
|
||||||
@new_message = Message.new
|
@new_message = Message.new
|
||||||
|
|
||||||
|
@direction = :in
|
||||||
|
@messages = @user.undeleted_received_messages
|
||||||
|
|
||||||
if params[:to]
|
if params[:to]
|
||||||
@new_message.recipient_username = params[:to]
|
@new_message.recipient_username = params[:to]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sent
|
||||||
|
@cur_url = "/messages"
|
||||||
|
@title = "Messages Sent"
|
||||||
|
|
||||||
|
@direction = :out
|
||||||
|
@messages = @user.undeleted_sent_messages
|
||||||
|
|
||||||
|
@new_message = Message.new
|
||||||
|
|
||||||
|
render :action => "index"
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@cur_url = "/messages"
|
@cur_url = "/messages"
|
||||||
@title = "Messages"
|
@title = "Messages"
|
||||||
|
@ -59,10 +74,15 @@ class MessagesController < ApplicationController
|
||||||
@message.deleted_by_recipient = true
|
@message.deleted_by_recipient = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@message.save
|
@message.save!
|
||||||
|
|
||||||
flash[:success] = "Deleted message."
|
flash[:success] = "Deleted message."
|
||||||
return redirect_to "/messages"
|
|
||||||
|
if @message.author_user_id == @user.id
|
||||||
|
return redirect_to "/messages/sent"
|
||||||
|
else
|
||||||
|
return redirect_to "/messages"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def keep_as_new
|
def keep_as_new
|
||||||
|
|
|
@ -18,15 +18,15 @@ class Message < ActiveRecord::Base
|
||||||
|
|
||||||
before_create :assign_short_id
|
before_create :assign_short_id
|
||||||
after_create :deliver_reply_notifications
|
after_create :deliver_reply_notifications
|
||||||
after_save :check_for_both_deleted
|
|
||||||
after_save :update_unread_counts
|
after_save :update_unread_counts
|
||||||
|
after_save :check_for_both_deleted
|
||||||
|
|
||||||
def assign_short_id
|
def assign_short_id
|
||||||
self.short_id = ShortId.new(self.class).generate
|
self.short_id = ShortId.new(self.class).generate
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_both_deleted
|
def check_for_both_deleted
|
||||||
if self.deleted_by_author && self.deleted_by_recipient
|
if self.deleted_by_author? && self.deleted_by_recipient?
|
||||||
self.destroy
|
self.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,9 @@ class Moderation < ActiveRecord::Base
|
||||||
m = Message.new
|
m = Message.new
|
||||||
m.author_user_id = self.moderator_user_id
|
m.author_user_id = self.moderator_user_id
|
||||||
|
|
||||||
|
# mark as deleted by author so they don't fill up moderator message boxes
|
||||||
|
m.deleted_by_author = true
|
||||||
|
|
||||||
if self.story
|
if self.story
|
||||||
m.recipient_user_id = self.story.user_id
|
m.recipient_user_id = self.story.user_id
|
||||||
m.subject = "Your story has been edited by a moderator"
|
m.subject = "Your story has been edited by a moderator"
|
||||||
|
@ -50,8 +53,6 @@ class Moderation < ActiveRecord::Base
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# so this will be deleted when the recipient deletes it
|
|
||||||
m.deleted_by_author = true
|
|
||||||
m.save
|
m.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ class User < ActiveRecord::Base
|
||||||
has_many :stories,
|
has_many :stories,
|
||||||
:include => :user
|
:include => :user
|
||||||
has_many :comments
|
has_many :comments
|
||||||
has_many :authored_messages,
|
has_many :sent_messages,
|
||||||
:class_name => "Message",
|
:class_name => "Message",
|
||||||
:foreign_key => "author_user_id"
|
:foreign_key => "author_user_id"
|
||||||
has_many :received_messages,
|
has_many :received_messages,
|
||||||
|
@ -101,9 +101,11 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def undeleted_received_messages
|
def undeleted_received_messages
|
||||||
received_messages.where([ "((recipient_user_id = ? AND " <<
|
received_messages.where(:deleted_by_recipient => false)
|
||||||
"deleted_by_recipient = 0) OR (author_user_id = ? AND " <<
|
end
|
||||||
"deleted_by_author = 0))", self.id, self.id ])
|
|
||||||
|
def undeleted_sent_messages
|
||||||
|
sent_messages.where(:deleted_by_author => 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initiate_password_reset_for_ip(ip)
|
def initiate_password_reset_for_ip(ip)
|
||||||
|
|
|
@ -66,16 +66,21 @@
|
||||||
<div id="headerright" class="<%= @user ? "loggedin" : "" %>">
|
<div id="headerright" class="<%= @user ? "loggedin" : "" %>">
|
||||||
<span class="headerlinks">
|
<span class="headerlinks">
|
||||||
<% if @user %>
|
<% if @user %>
|
||||||
<a href="/filters">Filters</a>
|
<a href="/filters" <%= @cur_url == "/filters" ?
|
||||||
|
raw("class=\"cur_url\"") : "" %>>Filters</a>
|
||||||
|
|
||||||
<% if (count = @user.unread_message_count) > 0 %>
|
<% if (count = @user.unread_message_count) > 0 %>
|
||||||
<a href="/messages" class="new_messages"><%= count %> New
|
<a href="/messages" class="new_messages <%= @cur_url == "/messages" ?
|
||||||
Message<%= count == 1 ? "" : "s" %></a>
|
"cur_url" : "" %>"><%= count %> New Message<%= count == 1 ? "" :
|
||||||
|
"s" %></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="/messages">Messages</a>
|
<a href="/messages" <%= @cur_url == "/messages" ?
|
||||||
|
raw("class=\"cur_url\"") : "" %>>Messages</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<a href="/settings"><%= @user.username %> (<%= @user.karma %>)</a>
|
<a href="/settings" <%= @cur_url == "/settings" ?
|
||||||
|
raw("class=\"cur_url\"") : "" %>><%= @user.username %>
|
||||||
|
(<%= @user.karma %>)</a>
|
||||||
|
|
||||||
<%= link_to "Logout", { :controller => "login", :action => "logout" },
|
<%= link_to "Logout", { :controller => "login", :action => "logout" },
|
||||||
:data => { :confirm => "Are you sure you want to logout?" },
|
:data => { :confirm => "Are you sure you want to logout?" },
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
<div class="box wide">
|
<div class="box wide">
|
||||||
|
<div class="legend" style="float: right;">
|
||||||
|
<% if @direction == :out %>
|
||||||
|
<a href="/messages">View Received</a>
|
||||||
|
<% else %>
|
||||||
|
<a href="/messages/sent">View Sent</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
<div class="legend">
|
<div class="legend">
|
||||||
Private Messages
|
Private Messages
|
||||||
|
<% if @direction == :out %>
|
||||||
|
Sent
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if @user.undeleted_received_messages.any? %>
|
<% if @messages.any? %>
|
||||||
<table class="data zebra" width="100%" cellspacing=0>
|
<table class="data zebra" width="100%" cellspacing=0>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="15%">From</th>
|
<th width="15%"><%= @direction == :in ? "From" : "To" %></th>
|
||||||
<th width="20%">Sent</th>
|
<th width="20%"><%= @direction == :in ? "Received" : "Sent" %></th>
|
||||||
<th width="60%">Subject</th>
|
<th width="60%">Subject</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% @user.undeleted_received_messages.each do |message| %>
|
<% @messages.includes(:author, :recipient).each do |message| %>
|
||||||
<tr class="<%= message.has_been_read? ? "" : "bold" %>">
|
<tr class="<%= message.has_been_read? ? "" : "bold" %>">
|
||||||
<td><a href="/u/<%= message.author.username %>"><%=
|
<td><% if @direction == :in %>
|
||||||
message.author.username %></a></td>
|
<a href="/u/<%= message.author.username %>"><%=
|
||||||
|
message.author.username %></a>
|
||||||
|
<% else %>
|
||||||
|
<a href="/u/<%= message.recipient.username %>"><%=
|
||||||
|
message.recipient.username %></a>
|
||||||
|
<% end %></td>
|
||||||
<td><%= time_ago_in_words(message.created_at) %> ago</td>
|
<td><%= time_ago_in_words(message.created_at) %> ago</td>
|
||||||
<td><a href="/messages/<%= message.short_id %>"><%= message.subject
|
<td><a href="/messages/<%= message.short_id %>"><%= message.subject
|
||||||
%></a></td>
|
%></a></td>
|
||||||
|
@ -22,7 +37,8 @@
|
||||||
</table>
|
</table>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>
|
<p>
|
||||||
You do not have any private messages.
|
You do not have any <%= @direction == :in ? "" : "sent" %> private
|
||||||
|
messages.
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
<div class="box wide">
|
<div class="box wide">
|
||||||
<div class="legend" style="float: right;">
|
<div class="legend" style="float: right;">
|
||||||
<a href="/messages">Back to Messages</a>
|
<% if @message.author_user_id == @user.id %>
|
||||||
|
<a href="/messages/sent">Back to Sent Messages</a>
|
||||||
|
<% else %>
|
||||||
|
<a href="/messages">Back to Messages</a>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="legend">
|
<div class="legend">
|
||||||
|
|
|
@ -58,6 +58,7 @@ Lobsters::Application.routes.draw do
|
||||||
post "/comments/post_to/:story_id" => "comments#create"
|
post "/comments/post_to/:story_id" => "comments#create"
|
||||||
post "/comments/preview_to/:story_id" => "comments#preview_new"
|
post "/comments/preview_to/:story_id" => "comments#preview_new"
|
||||||
|
|
||||||
|
get "/messages/sent" => "messages#sent"
|
||||||
resources :messages do
|
resources :messages do
|
||||||
post "keep_as_new"
|
post "keep_as_new"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue