Sha256: afcab3a924c8086629341fbc6e41ba9a96360e4c6a313809c27797e4c0e0b6ba

Contents?: true

Size: 1.14 KB

Versions: 21

Compression:

Stored size: 1.14 KB

Contents

class MailboxController < ApplicationController
  before_filter :authenticate_user!

  def index
    if user_signed_in?
      @messages = current_user.mailbox.inbox
      @messages.each{|m| m.mark_as_read(current_user)}
    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.notifications_path
  end

  def destroy
    if current_user
      msg = Mailboxer::Conversation.find(params[:id])
      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.notifications_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

21 entries across 21 versions & 1 rubygems

Version Path
sufia-6.2.0 app/controllers/mailbox_controller.rb
sufia-6.1.0 app/controllers/mailbox_controller.rb
sufia-5.0.0 app/controllers/mailbox_controller.rb
sufia-6.0.0 app/controllers/mailbox_controller.rb
sufia-6.0.0.rc4 app/controllers/mailbox_controller.rb
sufia-6.0.0.rc3 app/controllers/mailbox_controller.rb
sufia-5.0.0.rc1 app/controllers/mailbox_controller.rb
sufia-6.0.0.rc2 app/controllers/mailbox_controller.rb
sufia-6.0.0.rc1 app/controllers/mailbox_controller.rb
sufia-4.3.1 app/controllers/mailbox_controller.rb
sufia-6.0.0.beta1 app/controllers/mailbox_controller.rb
sufia-4.2.0 app/controllers/mailbox_controller.rb
sufia-4.1.0 app/controllers/mailbox_controller.rb
sufia-4.0.1 app/controllers/mailbox_controller.rb
sufia-4.0.0 app/controllers/mailbox_controller.rb
sufia-4.0.0.rc2 app/controllers/mailbox_controller.rb
sufia-4.0.0.rc1 app/controllers/mailbox_controller.rb
sufia-4.0.0.beta4 app/controllers/mailbox_controller.rb
sufia-4.0.0.beta3 app/controllers/mailbox_controller.rb
sufia-4.0.0.beta2 app/controllers/mailbox_controller.rb