]> git.openstreetmap.org Git - rails.git/commitdiff
Add the ability for a recipient to (logically) delete a message from
authorTom Hughes <tom@compton.nu>
Thu, 23 Jul 2009 15:22:44 +0000 (15:22 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 23 Jul 2009 15:22:44 +0000 (15:22 +0000)
their INBOX so they no longer see it.

app/controllers/message_controller.rb
app/models/user.rb
app/views/message/_message_summary.html.erb
app/views/message/inbox.html.erb
config/locales/en.yml
config/routes.rb
db/migrate/036_add_visible_to_message.rb [new file with mode: 0644]

index e1062bc9f6e89559e322d63a9a85d176b74dcaf0..ba9e9f1e2171d16d41a6c844fc7f4d95356c53fa 100644 (file)
@@ -104,5 +104,20 @@ class MessageController < ApplicationController
     @title = t'message.no_such_user.title'
     render :action => 'no_such_user', :status => :not_found
   end
     @title = t'message.no_such_user.title'
     render :action => 'no_such_user', :status => :not_found
   end
+
+  # Delete the message.
+  def delete
+    if params[:message_id]
+      id = params[:message_id]
+      message = Message.find_by_id(id)
+      message.visible = false
+      if message.save
+        flash[:notice] = t 'message.delete.deleted'
+        redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+      end
+    end
+  rescue ActiveRecord::RecordNotFound
+    @title = t'message.no_such_user.title'
+    render :action => 'no_such_user', :status => :not_found
+  end
 end
 end
index 241c1396ffeca73a51e25a40a72a779ee41a67f7..68738a8f071e9bc51c34b5a319b566e81ee106a9 100644 (file)
@@ -3,8 +3,8 @@ class User < ActiveRecord::Base
 
   has_many :traces
   has_many :diary_entries, :order => 'created_at DESC'
 
   has_many :traces
   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 => false}, :order => 'sent_on DESC'
+  has_many :messages, :foreign_key => :to_user_id, :conditions => { :visible => true }, :order => 'sent_on DESC'
+  has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :message_read => false }, :order => 'sent_on DESC'
   has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :order => 'sent_on DESC'
   has_many :friends, :include => :befriendee, :conditions => ["users.visible = ?", true]
   has_many :tokens, :class_name => "UserToken"
   has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :order => 'sent_on DESC'
   has_many :friends, :include => :befriendee, :conditions => ["users.visible = ?", true]
   has_many :tokens, :class_name => "UserToken"
index 49190fd936e16326f57cd2757a8069ad85169411..b00329d6e927e6b69f56d234d149ad5c22850261 100644 (file)
@@ -10,4 +10,5 @@
     <td><%= button_to t('message.message_summary.read_button'), :controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read' %></td>
   <% end %>
   <td><%= button_to t('message.message_summary.reply_button'), :controller => 'message', :action => 'reply', :message_id => message_summary.id %></td>
     <td><%= button_to t('message.message_summary.read_button'), :controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read' %></td>
   <% end %>
   <td><%= button_to t('message.message_summary.reply_button'), :controller => 'message', :action => 'reply', :message_id => message_summary.id %></td>
+  <td><%= button_to t('message.message_summary.delete_button'), :controller => 'message', :action => 'delete', :message_id => message_summary.id %></td>
 </tr>
 </tr>
index e75d6c1ecb8e4700174ad26b759b370abc98cbb4..2a97b7bbd2d1f9d6ea782a61a646d7e4417b66da 100644 (file)
@@ -11,6 +11,7 @@
         <th><%= t'message.inbox.date' %></th>
         <th></th>
         <th></th>
         <th><%= t'message.inbox.date' %></th>
         <th></th>
         <th></th>
+        <th></th>
       </tr>
       <%= render :partial => "message_summary", :collection => @user.messages %>
     </table>
       </tr>
       <%= render :partial => "message_summary", :collection => @user.messages %>
     </table>
index 5ae59e38d63d0b90b42b0e26c3475795e8949a64..06c691f9f026cec37c4255f33a4703f62342c680 100644 (file)
@@ -547,6 +547,7 @@ en:
       unread_button: "Mark as unread"
       read_button: "Mark as read"
       reply_button: "Reply"
       unread_button: "Mark as unread"
       read_button: "Mark as read"
       reply_button: "Reply"
+      delete_button: "Delete"
     new:
       title: "Send message"
       send_message_to: "Send a new message to {{name}}"
     new:
       title: "Send message"
       send_message_to: "Send a new message to {{name}}"
@@ -585,6 +586,8 @@ en:
     mark:
       as_read: "Message marked as read"
       as_unread: "Message marked as unread"
     mark:
       as_read: "Message marked as read"
       as_unread: "Message marked as unread"
+    delete:
+      deleted: "Message deleted"
   site:
     index:
       js_1: "You are either using a browser that doesn't support javascript, or you have disabled javascript."
   site:
     index:
       js_1: "You are either using a browser that doesn't support javascript, or you have disabled javascript."
index f26a1503270479c94aafb3f926a6205acc1c788c..5ac2d744a77e73f7f7abbf8b4ac7fc63b795b735 100644 (file)
@@ -194,6 +194,7 @@ ActionController::Routing::Routes.draw do |map|
   map.connect '/message/read/:message_id', :controller => 'message', :action => 'read'
   map.connect '/message/mark/:message_id', :controller => 'message', :action => 'mark'
   map.connect '/message/reply/:message_id', :controller => 'message', :action => 'reply'
   map.connect '/message/read/:message_id', :controller => 'message', :action => 'read'
   map.connect '/message/mark/:message_id', :controller => 'message', :action => 'mark'
   map.connect '/message/reply/:message_id', :controller => 'message', :action => 'reply'
+  map.connect '/message/delete/:message_id', :controller => 'message', :action => 'delete'
 
   # fall through
   map.connect ':controller/:id/:action'
 
   # fall through
   map.connect ':controller/:id/:action'
diff --git a/db/migrate/036_add_visible_to_message.rb b/db/migrate/036_add_visible_to_message.rb
new file mode 100644 (file)
index 0000000..22b1219
--- /dev/null
@@ -0,0 +1,9 @@
+class AddVisibleToMessage < ActiveRecord::Migration
+  def self.up
+    add_column :messages, :visible, :boolean, :default => true, :null => false
+  end
+
+  def self.down
+    remove_column :messages, :visible
+  end
+end