Class: Alerter::Mailbox

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifiable) ⇒ Mailbox

Initializer method



5
6
7
# File 'app/models/alerter/mailbox.rb', line 5

def initialize(notifiable)
  @notifiable = notifiable
end

Instance Attribute Details

#notifiableObject (readonly)

Returns the value of attribute notifiable.



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

def notifiable
  @notifiable
end

Instance Method Details

#all_messages(options = {}) ⇒ Object

Returns the messages for the messageable



10
11
12
13
14
15
16
17
18
# File 'app/models/alerter/mailbox.rb', line 10

def all_messages(options = {})
  #:type => nil is a hack not to give Messages as Notifications
  messages = Alerter::Message.receipts(@notifiable).where(:type => nil).order("alerter_messages.created_at DESC")
  if options[:read] == false || options[:unread]
    messages = messages.unread
  end

  messages
end

#inbox(options = {}) ⇒ Object

Returns the messages in the inbox of notifiable

Same as conversations(=> ‘inbox’)



44
45
46
47
# File 'app/models/alerter/mailbox.rb', line 44

def inbox(options={})
  options = options.merge(:mailbox_type => 'inbox')
  messages(options)
end

#messages(options = {}) ⇒ Object

Returns the conversations for the messageable

Options

  • :mailbox_type

  • “inbox”

  • “trash”

  • :read=false

  • :unread=true



31
32
33
34
35
36
37
38
39
# File 'app/models/alerter/mailbox.rb', line 31

def messages(options = {})
  messages = get_messages(options[:mailbox_type])

  if options[:read] == false || options[:unread]
    messages = messages.unread #(notifiable)
  end

  messages
end

#receipts(options = {}) ⇒ Object

Returns all the receipts of notifiable from Messages



56
57
58
# File 'app/models/alerter/mailbox.rb', line 56

def receipts(options = {})
  Alerter::Receipt.where(options).recipient(notifiable)
end

#trash(options = {}) ⇒ Object



49
50
51
52
# File 'app/models/alerter/mailbox.rb', line 49

def trash(options={})
  options = options.merge(:mailbox_type => 'trash')
  messages(options)
end