]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/message_controller.rb
Ignore traces which have not been inserted yet when calculating
[rails.git] / app / controllers / message_controller.rb
index e1062bc9f6e89559e322d63a9a85d176b74dcaf0..db40cc03f7922b33625eb7ed9f17391e3b86b6a0 100644 (file)
@@ -104,5 +104,26 @@ class MessageController < ApplicationController
     @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.from_user_visible = false if message.sender == @user
+      message.to_user_visible = false if message.recipient == @user
+      if message.save
+        flash[:notice] = t 'message.delete.deleted'
+
+        if params[:referer]
+          redirect_to params[:referer]
+        else
+          redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+        end
+      end
+    end
+  rescue ActiveRecord::RecordNotFound
+    @title = t'message.no_such_user.title'
+    render :action => 'no_such_user', :status => :not_found
+  end
 end