Sha256: 4f123a8978751527917d2238195df544639b8cf88f2bb0909c1745d9d1c00128

Contents?: true

Size: 926 Bytes

Versions: 33

Compression:

Stored size: 926 Bytes

Contents

class UserMailbox
  attr_reader :user

  def initialize(user)
    @user = user
  end

  def inbox
    messages = user.mailbox.inbox
    messages.each { |m| m.mark_as_read(user) }
  end

  def delete_all
    user.mailbox.inbox.each do |msg|
      delete_message(msg)
    end
    empty_trash(user)
  end

  def destroy(message_id)
    msg = Mailboxer::Conversation.find(message_id)
    return "You do not have privileges to delete the notification..." unless msg.participants.include? user
    delete_message(msg)
    empty_trash(msg.participants[0])
    nil
  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 do |conv|
        conv.messages.each do |notify|
          notify.receipts.each(&:delete)
          notify.delete
        end
        conv.delete
      end
    end
end

Version data entries

33 entries across 33 versions & 3 rubygems

Version Path
sufia-7.1.0 app/models/user_mailbox.rb
sufia-7.0.0 app/models/user_mailbox.rb
sufia-7.0.0.rc2 app/models/user_mailbox.rb
sufia-7.0.0.rc1 app/models/user_mailbox.rb
sufia-7.0.0.beta4 app/models/user_mailbox.rb
sufia-7.0.0.beta3 app/models/user_mailbox.rb
sufia-7.0.0.beta2 app/models/user_mailbox.rb
sufia-7.0.0.beta1 app/models/user_mailbox.rb
sufia-6.6.1 app/models/user_mailbox.rb
sufia-6.6.0 app/models/user_mailbox.rb
sufia-6.5.0 app/models/user_mailbox.rb
sufia-6.4.0 app/models/user_mailbox.rb
sufia-6.3.0 app/models/user_mailbox.rb