Class: Mailboxer::Receipt
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mailboxer::Receipt
- Defined in:
- app/models/mailboxer/receipt.rb
Class Method Summary collapse
-
.mark_as_deleted(options = {}) ⇒ Object
Marks the receipt as deleted.
-
.mark_as_not_deleted(options = {}) ⇒ Object
Marks the receipt as not deleted.
-
.mark_as_read(options = {}) ⇒ Object
Marks all the receipts from the relation as read.
-
.mark_as_unread(options = {}) ⇒ Object
Marks all the receipts from the relation as unread.
-
.move_to_inbox(options = {}) ⇒ Object
Moves all the receipts from the relation to inbox.
-
.move_to_sentbox(options = {}) ⇒ Object
Moves all the receipts from the relation to sentbox.
-
.move_to_trash(options = {}) ⇒ Object
Marks all the receipts from the relation as trashed.
-
.untrash(options = {}) ⇒ Object
Marks all the receipts from the relation as not trashed.
-
.update_receipts(updates, options = {}) ⇒ Object
This methods helps to do a update_all with table joins, not currently supported by rails.
Instance Method Summary collapse
-
#conversation ⇒ Object
Returns the conversation associated to the receipt if the notification is a Message.
-
#is_trashed? ⇒ Boolean
Returns if the participant have trashed the Notification.
-
#is_unread? ⇒ Boolean
Returns if the participant have read the Notification.
-
#mark_as_deleted ⇒ Object
Marks the receipt as deleted.
-
#mark_as_not_deleted ⇒ Object
Marks the receipt as not deleted.
-
#mark_as_read ⇒ Object
Marks the receipt as read.
-
#mark_as_unread ⇒ Object
Marks the receipt as unread.
-
#move_to_inbox ⇒ Object
Moves the receipt to inbox.
-
#move_to_sentbox ⇒ Object
Moves the receipt to sentbox.
-
#move_to_trash ⇒ Object
Marks the receipt as trashed.
-
#untrash ⇒ Object
Marks the receipt as not trashed.
Class Method Details
.mark_as_deleted(options = {}) ⇒ Object
Marks the receipt as deleted
56 57 58 |
# File 'app/models/mailboxer/receipt.rb', line 56 def mark_as_deleted(={}) update_receipts({:deleted => true}, ) end |
.mark_as_not_deleted(options = {}) ⇒ Object
Marks the receipt as not deleted
61 62 63 |
# File 'app/models/mailboxer/receipt.rb', line 61 def mark_as_not_deleted(={}) update_receipts({:deleted => false}, ) end |
.mark_as_read(options = {}) ⇒ Object
Marks all the receipts from the relation as read
36 37 38 |
# File 'app/models/mailboxer/receipt.rb', line 36 def mark_as_read(={}) update_receipts({:is_read => true}, ) end |
.mark_as_unread(options = {}) ⇒ Object
Marks all the receipts from the relation as unread
41 42 43 |
# File 'app/models/mailboxer/receipt.rb', line 41 def mark_as_unread(={}) update_receipts({:is_read => false}, ) end |
.move_to_inbox(options = {}) ⇒ Object
Moves all the receipts from the relation to inbox
66 67 68 |
# File 'app/models/mailboxer/receipt.rb', line 66 def move_to_inbox(={}) update_receipts({:mailbox_type => :inbox, :trashed => false}, ) end |
.move_to_sentbox(options = {}) ⇒ Object
Moves all the receipts from the relation to sentbox
71 72 73 |
# File 'app/models/mailboxer/receipt.rb', line 71 def move_to_sentbox(={}) update_receipts({:mailbox_type => :sentbox, :trashed => false}, ) end |
.move_to_trash(options = {}) ⇒ Object
Marks all the receipts from the relation as trashed
46 47 48 |
# File 'app/models/mailboxer/receipt.rb', line 46 def move_to_trash(={}) update_receipts({:trashed => true}, ) end |
.untrash(options = {}) ⇒ Object
Marks all the receipts from the relation as not trashed
51 52 53 |
# File 'app/models/mailboxer/receipt.rb', line 51 def untrash(={}) update_receipts({:trashed => false}, ) end |
.update_receipts(updates, options = {}) ⇒ Object
This methods helps to do a update_all with table joins, not currently supported by rails. According to the github ticket github.com/rails/rails/issues/522 it should be supported with 3.2.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/mailboxer/receipt.rb', line 78 def update_receipts(updates,={}) ids = where().map { |rcp| rcp.id } unless ids.empty? conditions = [""].concat(ids) condition = "id = ? " ids.drop(1).each do condition << "OR id = ? " end conditions[0] = condition Mailboxer::Receipt.except(:where).except(:joins).where(conditions).update_all(updates) end end |
Instance Method Details
#conversation ⇒ Object
Returns the conversation associated to the receipt if the notification is a Message
134 135 136 |
# File 'app/models/mailboxer/receipt.rb', line 134 def conversation .conversation if .is_a? Mailboxer::Message end |
#is_trashed? ⇒ Boolean
Returns if the participant have trashed the Notification
144 145 146 |
# File 'app/models/mailboxer/receipt.rb', line 144 def is_trashed? trashed end |
#is_unread? ⇒ Boolean
Returns if the participant have read the Notification
139 140 141 |
# File 'app/models/mailboxer/receipt.rb', line 139 def is_unread? !is_read end |
#mark_as_deleted ⇒ Object
Marks the receipt as deleted
94 95 96 |
# File 'app/models/mailboxer/receipt.rb', line 94 def mark_as_deleted update_attributes(:deleted => true) end |
#mark_as_not_deleted ⇒ Object
Marks the receipt as not deleted
99 100 101 |
# File 'app/models/mailboxer/receipt.rb', line 99 def mark_as_not_deleted update_attributes(:deleted => false) end |
#mark_as_read ⇒ Object
Marks the receipt as read
104 105 106 |
# File 'app/models/mailboxer/receipt.rb', line 104 def mark_as_read update_attributes(:is_read => true) end |
#mark_as_unread ⇒ Object
Marks the receipt as unread
109 110 111 |
# File 'app/models/mailboxer/receipt.rb', line 109 def mark_as_unread update_attributes(:is_read => false) end |
#move_to_inbox ⇒ Object
Moves the receipt to inbox
124 125 126 |
# File 'app/models/mailboxer/receipt.rb', line 124 def move_to_inbox update_attributes(:mailbox_type => :inbox, :trashed => false) end |
#move_to_sentbox ⇒ Object
Moves the receipt to sentbox
129 130 131 |
# File 'app/models/mailboxer/receipt.rb', line 129 def move_to_sentbox update_attributes(:mailbox_type => :sentbox, :trashed => false) end |
#move_to_trash ⇒ Object
Marks the receipt as trashed
114 115 116 |
# File 'app/models/mailboxer/receipt.rb', line 114 def move_to_trash update_attributes(:trashed => true) end |
#untrash ⇒ Object
Marks the receipt as not trashed
119 120 121 |
# File 'app/models/mailboxer/receipt.rb', line 119 def untrash update_attributes(:trashed => false) end |