Class: UserMailbox

Inherits:
Object
  • Object
show all
Defined in:
app/models/user_mailbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ UserMailbox

Returns a new instance of UserMailbox.



4
5
6
# File 'app/models/user_mailbox.rb', line 4

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



2
3
4
# File 'app/models/user_mailbox.rb', line 2

def user
  @user
end

Instance Method Details

#delete_allObject



13
14
15
16
17
18
# File 'app/models/user_mailbox.rb', line 13

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

#destroy(message_id) ⇒ Object



20
21
22
23
24
25
26
# File 'app/models/user_mailbox.rb', line 20

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

#inboxObject



8
9
10
11
# File 'app/models/user_mailbox.rb', line 8

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