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
hyrax-1.1.1 app/models/user_mailbox.rb
hyrax-1.1.0 app/models/user_mailbox.rb
sufia-7.4.1 app/models/user_mailbox.rb
hyrax-1.0.5 app/models/user_mailbox.rb
sufia-7.4.0 app/models/user_mailbox.rb
hyrax-2.0.0.beta1 app/models/user_mailbox.rb
hyrax-1.0.4 app/models/user_mailbox.rb
hyrax-1.0.3 app/models/user_mailbox.rb
hyrax-1.0.2 app/models/user_mailbox.rb
hyrax-1.0.1 app/models/user_mailbox.rb
hyrax-1.0.0.rc2 app/models/user_mailbox.rb
sufia-7.3.1 app/models/user_mailbox.rb
hyrax-1.0.0.rc1 app/models/user_mailbox.rb
sufia-7.3.0 app/models/user_mailbox.rb
sufia-7.3.0.rc3 app/models/user_mailbox.rb
sufia-7.3.0.rc2 app/models/user_mailbox.rb
sufia-7.3.0.rc1 app/models/user_mailbox.rb
test_hyrax-0.0.1.alpha app/models/user_mailbox.rb
sufia-7.2.0 app/models/user_mailbox.rb
sufia-6.7.0 app/models/user_mailbox.rb