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.
-
#conversations_with(other_messageable) ⇒ Object
Returns the conversations between messageable and other 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
37 38 39 40 41 42 43 44 45 |
# File 'app/models/mailboxer/mailbox.rb', line 37 def conversations( = {}) conv = get_conversations([:mailbox_type]) if [:read] == false || [:unread] conv = conv.unread() end conv end |
#conversations_with(other_messageable) ⇒ Object
Returns the conversations between messageable and other messageable
21 22 23 |
# File 'app/models/mailboxer/mailbox.rb', line 21 def conversations_with() Mailboxer::Conversation.between(, ) end |
#empty_trash(options = {}) ⇒ Object
Deletes all the messages in the trash of messageable.
77 78 79 80 81 |
# File 'app/models/mailboxer/mailbox.rb', line 77 def empty_trash( = {}) trash().each do |conversation| conversation.mark_as_deleted() end end |
#has_conversation?(conversation) ⇒ Boolean
Returns if messageable is a participant of conversation
84 85 86 |
# File 'app/models/mailboxer/mailbox.rb', line 84 def has_conversation?(conversation) conversation.is_participant?() end |
#inbox(options = {}) ⇒ Object
Returns the conversations in the inbox of messageable
Same as conversations(=> ‘inbox’)
50 51 52 53 |
# File 'app/models/mailboxer/mailbox.rb', line 50 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
94 95 96 |
# File 'app/models/mailboxer/mailbox.rb', line 94 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
89 90 91 |
# File 'app/models/mailboxer/mailbox.rb', line 89 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(:created_at => :desc, :id => :desc) if [:read] == false || [:unread] notifs = notifs.unread end notifs end |
#receipts(options = {}) ⇒ Object
Returns all the receipts of messageable, from Messages and Notifications
72 73 74 |
# File 'app/models/mailboxer/mailbox.rb', line 72 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
106 107 108 109 110 111 112 113 |
# File 'app/models/mailboxer/mailbox.rb', line 106 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’)
58 59 60 61 |
# File 'app/models/mailboxer/mailbox.rb', line 58 def sentbox(={}) = .merge(:mailbox_type => 'sentbox') conversations() end |
#trash(options = {}) ⇒ Object
Returns the conversations in the trash of messageable
Same as conversations(=> ‘trash’)
66 67 68 69 |
# File 'app/models/mailboxer/mailbox.rb', line 66 def trash(={}) = .merge(:mailbox_type => 'trash') conversations() end |