Class: Mailboxer::Mailbox
- Inherits:
-
Object
- Object
- Mailboxer::Mailbox
- Defined in:
- app/models/mailboxer/mailbox.rb
Instance Attribute Summary collapse
-
#messageable ⇒ Object
readonly
Returns the value of attribute messageable.
Instance Method Summary collapse
-
#conversations(options = {}) ⇒ Object
Returns the conversations for the messageable.
-
#empty_trash(options = {}) ⇒ Object
Deletes all the messages in the trash of messageable.
-
#has_conversation?(conversation) ⇒ Boolean
Returns if messageable is a participant of conversation.
-
#inbox(options = {}) ⇒ Object
Returns the conversations in the inbox of messageable.
-
#initialize(messageable) ⇒ Mailbox
constructor
Initializer method.
-
#is_completely_trashed?(conversation) ⇒ Boolean
Returns true if messageable has trashed all the messages of the conversation.
-
#is_trashed?(conversation) ⇒ Boolean
Returns true if messageable has at least one trashed message of the conversation.
-
#notifications(options = {}) ⇒ Object
Returns the notifications for the messageable.
-
#receipts(options = {}) ⇒ Object
Returns all the receipts of messageable, from Messages and Notifications.
-
#receipts_for(object) ⇒ Object
Returns the receipts of object for messageable as a ActiveRecord::Relation.
-
#sentbox(options = {}) ⇒ Object
Returns the conversations in the sentbox of messageable.
-
#trash(options = {}) ⇒ Object
Returns the conversations in the trash of messageable.
Constructor Details
#initialize(messageable) ⇒ Mailbox
Initializer method
5 6 7 |
# File 'app/models/mailboxer/mailbox.rb', line 5 def initialize() @messageable = end |
Instance Attribute Details
#messageable ⇒ Object (readonly)
Returns the value of attribute messageable.
2 3 4 |
# File 'app/models/mailboxer/mailbox.rb', line 2 def @messageable end |
Instance Method Details
#conversations(options = {}) ⇒ Object
Returns the conversations for the messageable
Options
-
:mailbox_type
-
“inbox”
-
“sentbox”
-
“trash”
-
:read=false
-
:unread=true
32 33 34 35 36 37 38 39 40 |
# File 'app/models/mailboxer/mailbox.rb', line 32 def conversations( = {}) conv = get_conversations([:mailbox_type]) if [:read] == false || [:unread] conv = conv.unread() end conv end |
#empty_trash(options = {}) ⇒ Object
Deletes all the messages in the trash of messageable. NOT IMPLEMENTED.
72 73 74 75 |
# File 'app/models/mailboxer/mailbox.rb', line 72 def empty_trash( = {}) #TODO false end |
#has_conversation?(conversation) ⇒ Boolean
Returns if messageable is a participant of conversation
78 79 80 |
# File 'app/models/mailboxer/mailbox.rb', line 78 def has_conversation?(conversation) conversation.is_participant?() end |
#inbox(options = {}) ⇒ Object
Returns the conversations in the inbox of messageable
Same as conversations(=> ‘inbox’)
45 46 47 48 |
# File 'app/models/mailboxer/mailbox.rb', line 45 def inbox(={}) = .merge(:mailbox_type => 'inbox') conversations() end |
#is_completely_trashed?(conversation) ⇒ Boolean
Returns true if messageable has trashed all the messages of the conversation
88 89 90 |
# File 'app/models/mailboxer/mailbox.rb', line 88 def is_completely_trashed?(conversation) conversation.is_completely_trashed?() end |
#is_trashed?(conversation) ⇒ Boolean
Returns true if messageable has at least one trashed message of the conversation
83 84 85 |
# File 'app/models/mailboxer/mailbox.rb', line 83 def is_trashed?(conversation) conversation.is_trashed?() end |
#notifications(options = {}) ⇒ Object
Returns the notifications for the messageable
10 11 12 13 14 15 16 17 18 |
# File 'app/models/mailboxer/mailbox.rb', line 10 def notifications( = {}) #:type => nil is a hack not to give Messages as Notifications notifs = Mailboxer::Notification.recipient().where(:type => nil).order("mailboxer_notifications.created_at DESC") if [:read] == false || [:unread] notifs = notifs.unread end notifs end |
#receipts(options = {}) ⇒ Object
Returns all the receipts of messageable, from Messages and Notifications
67 68 69 |
# File 'app/models/mailboxer/mailbox.rb', line 67 def receipts( = {}) Mailboxer::Receipt.where().recipient() end |
#receipts_for(object) ⇒ Object
Returns the receipts of object for messageable as a ActiveRecord::Relation
Object can be:
-
A Message
-
A Notification
-
A Conversation
If object isn’t one of the above, a nil will be returned
100 101 102 103 104 105 106 107 |
# File 'app/models/mailboxer/mailbox.rb', line 100 def receipts_for(object) case object when Mailboxer::Message, Mailboxer::Notification object.receipt_for() when Mailboxer::Conversation object.receipts_for() end end |
#sentbox(options = {}) ⇒ Object
Returns the conversations in the sentbox of messageable
Same as conversations(=> ‘sentbox’)
53 54 55 56 |
# File 'app/models/mailboxer/mailbox.rb', line 53 def sentbox(={}) = .merge(:mailbox_type => 'sentbox') conversations() end |
#trash(options = {}) ⇒ Object
Returns the conversations in the trash of messageable
Same as conversations(=> ‘trash’)
61 62 63 64 |
# File 'app/models/mailboxer/mailbox.rb', line 61 def trash(={}) = .merge(:mailbox_type => 'trash') conversations() end |