Sha256: 7936c4165b4725d8e0b2c72df074e0ebe298b6d156775dcc6104b6b220f29860

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

class MailboxController < ApplicationController
  before_filter :authenticate_user!

  def index
    if user_signed_in?
      inbox = current_user.mailbox.inbox
      @messages = inbox.all
      current_user.mark_as_read @messages
    else
      @messages =[]
    end 
  end

  def delete_all     
     current_user.mailbox.inbox.each do |msg|
        delete_message(msg)
     end
     empty_trash(current_user)
     redirect_to sufia.mailbox_path
  end

  def delete
    if (current_user)
      msg = Conversation.find(params[:uid])
      if (msg.participants[0] == current_user) || (msg.participants[1] == current_user)
         delete_message(msg)
         empty_trash(msg.participants[0])
      end
   else 
      flash[:alert] = "You do not have privileges to delete the notification..."
   end
   redirect_to sufia.mailbox_path
  end

private 

  def delete_message (msg)
      msg.move_to_trash(msg.participants[0])
      msg.move_to_trash(msg.participants[1])
  end
  
  def empty_trash (user)
    user.mailbox.trash.each { |conv| conv.messages.each {|notify| notify.receipts.each { |receipt| receipt.delete}; notify.delete}; conv.delete}
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sufia-3.2.1 app/controllers/mailbox_controller.rb
sufia-3.1.3 app/controllers/mailbox_controller.rb