Class: Mailboxer::Receipt

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
PgSearch
Defined in:
app/models/mailboxer/receipt.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mark_as_deleted(options = {}) ⇒ Object

Marks the receipt as deleted



55
56
57
# File 'app/models/mailboxer/receipt.rb', line 55

def mark_as_deleted(options={})
  update_receipts({:deleted => true}, options)
end

.mark_as_not_deleted(options = {}) ⇒ Object

Marks the receipt as not deleted



60
61
62
# File 'app/models/mailboxer/receipt.rb', line 60

def mark_as_not_deleted(options={})
  update_receipts({:deleted => false}, options)
end

.mark_as_read(options = {}) ⇒ Object

Marks all the receipts from the relation as read



35
36
37
# File 'app/models/mailboxer/receipt.rb', line 35

def mark_as_read(options={})
  update_receipts({:is_read => true}, options)
end

.mark_as_unread(options = {}) ⇒ Object

Marks all the receipts from the relation as unread



40
41
42
# File 'app/models/mailboxer/receipt.rb', line 40

def mark_as_unread(options={})
  update_receipts({:is_read => false}, options)
end

.move_to_inbox(options = {}) ⇒ Object

Moves all the receipts from the relation to inbox



65
66
67
# File 'app/models/mailboxer/receipt.rb', line 65

def move_to_inbox(options={})
  update_receipts({:mailbox_type => :inbox, :trashed => false}, options)
end

.move_to_sentbox(options = {}) ⇒ Object

Moves all the receipts from the relation to sentbox



70
71
72
# File 'app/models/mailboxer/receipt.rb', line 70

def move_to_sentbox(options={})
  update_receipts({:mailbox_type => :sentbox, :trashed => false}, options)
end

.move_to_trash(options = {}) ⇒ Object

Marks all the receipts from the relation as trashed



45
46
47
# File 'app/models/mailboxer/receipt.rb', line 45

def move_to_trash(options={})
  update_receipts({:trashed => true}, options)
end

.untrash(options = {}) ⇒ Object

Marks all the receipts from the relation as not trashed



50
51
52
# File 'app/models/mailboxer/receipt.rb', line 50

def untrash(options={})
  update_receipts({:trashed => false}, options)
end

.update_receipts(updates, options = {}) ⇒ Object



74
75
76
77
# File 'app/models/mailboxer/receipt.rb', line 74

def update_receipts(updates, options={})
  ids = where(options).pluck(:id)
  Mailboxer::Receipt.where(:id => ids).update_all(updates) unless ids.empty?
end

Instance Method Details

#conversationObject

Returns the conversation associated to the receipt if the notification is a Message



122
123
124
# File 'app/models/mailboxer/receipt.rb', line 122

def conversation
  message.conversation if message.is_a? Mailboxer::Message
end

#is_trashed?Boolean

Returns if the participant have trashed the Notification

Returns:

  • (Boolean)


132
133
134
# File 'app/models/mailboxer/receipt.rb', line 132

def is_trashed?
  trashed
end

#is_unread?Boolean

Returns if the participant have read the Notification

Returns:

  • (Boolean)


127
128
129
# File 'app/models/mailboxer/receipt.rb', line 127

def is_unread?
  !is_read
end

#mark_as_deletedObject

Marks the receipt as deleted



82
83
84
# File 'app/models/mailboxer/receipt.rb', line 82

def mark_as_deleted
  update_attributes(:deleted => true)
end

#mark_as_not_deletedObject

Marks the receipt as not deleted



87
88
89
# File 'app/models/mailboxer/receipt.rb', line 87

def mark_as_not_deleted
  update_attributes(:deleted => false)
end

#mark_as_readObject

Marks the receipt as read



92
93
94
# File 'app/models/mailboxer/receipt.rb', line 92

def mark_as_read
  update_attributes(:is_read => true)
end

#mark_as_unreadObject

Marks the receipt as unread



97
98
99
# File 'app/models/mailboxer/receipt.rb', line 97

def mark_as_unread
  update_attributes(:is_read => false)
end

#move_to_inboxObject

Moves the receipt to inbox



112
113
114
# File 'app/models/mailboxer/receipt.rb', line 112

def move_to_inbox
  update_attributes(:mailbox_type => :inbox, :trashed => false)
end

#move_to_sentboxObject

Moves the receipt to sentbox



117
118
119
# File 'app/models/mailboxer/receipt.rb', line 117

def move_to_sentbox
  update_attributes(:mailbox_type => :sentbox, :trashed => false)
end

#move_to_trashObject

Marks the receipt as trashed



102
103
104
# File 'app/models/mailboxer/receipt.rb', line 102

def move_to_trash
  update_attributes(:trashed => true)
end

#untrashObject

Marks the receipt as not trashed



107
108
109
# File 'app/models/mailboxer/receipt.rb', line 107

def untrash
  update_attributes(:trashed => false)
end