Class: Mailbox
- Inherits:
-
Object
- Object
- Mailbox
- Defined in:
- app/models/mailbox.rb
Instance Attribute Summary collapse
-
#messageable ⇒ Object
readonly
Returns the value of attribute messageable.
-
#type ⇒ Object
Returns the value of attribute type.
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/mailbox.rb', line 5 def initialize() @messageable = end |
Instance Attribute Details
#messageable ⇒ Object (readonly)
Returns the value of attribute messageable.
3 4 5 |
# File 'app/models/mailbox.rb', line 3 def @messageable end |
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'app/models/mailbox.rb', line 2 def type @type end |
Instance Method Details
#conversations(options = {}) ⇒ Object
Returns the conversations for the messageable
Options
-
:mailbox_type
-
“inbox”
-
“sentbox”
-
“trash”
-
:read=false
-
:unread=true
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/mailbox.rb', line 27 def conversations( = {}) conv = Conversation.participant(@messageable) if [:mailbox_type].present? case [:mailbox_type] when 'inbox' conv = Conversation.inbox(@messageable) when 'sentbox' conv = Conversation.sentbox(@messageable) when 'trash' conv = Conversation.trash(@messageable) end end if ([:read].present? and [:read]==false) or ([:unread].present? and [:unread]==true) conv = conv.unread(@messageable) end return conv.uniq end |
#empty_trash(options = {}) ⇒ Object
Deletes all the messages in the trash of messageable. NOT IMPLEMENTED.
78 79 80 81 |
# File 'app/models/mailbox.rb', line 78 def empty_trash( = {}) #TODO return false end |
#has_conversation?(conversation) ⇒ Boolean
Returns if messageable is a participant of conversation
84 85 86 |
# File 'app/models/mailbox.rb', line 84 def has_conversation?(conversation) return conversation.is_participant?(@messageable) end |
#inbox(options = {}) ⇒ Object
Returns the conversations in the inbox of messageable
Same as conversations(=> ‘inbox’)
51 52 53 54 |
# File 'app/models/mailbox.rb', line 51 def inbox(={}) = .merge(:mailbox_type => 'inbox') return self.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/mailbox.rb', line 94 def is_completely_trashed?(conversation) return conversation.is_completely_trashed?(@messageable) end |
#is_trashed?(conversation) ⇒ Boolean
Returns true if messageable has at least one trashed message of the conversation
89 90 91 |
# File 'app/models/mailbox.rb', line 89 def is_trashed?(conversation) return conversation.is_trashed?(@messageable) end |
#notifications(options = {}) ⇒ Object
Returns the notifications for the messageable
10 11 12 13 |
# File 'app/models/mailbox.rb', line 10 def notifications( = {}) #:type => nil is a hack not to give Messages as Notifications return Notification.recipient(@messageable).where(:type => nil) end |
#receipts(options = {}) ⇒ Object
Returns all the receipts of messageable, from Messages and Notifications
73 74 75 |
# File 'app/models/mailbox.rb', line 73 def receipts( = {}) return Receipt.where().recipient(@messageable) 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 114 115 |
# File 'app/models/mailbox.rb', line 106 def receipts_for(object) case object when Message, Notification return object.receipt_for(@messageable) when Conversation return object.receipts_for(@messageable) else return nil end end |
#sentbox(options = {}) ⇒ Object
Returns the conversations in the sentbox of messageable
Same as conversations(=> ‘sentbox’)
59 60 61 62 |
# File 'app/models/mailbox.rb', line 59 def sentbox(={}) = .merge(:mailbox_type => 'sentbox') return self.conversations() end |
#trash(options = {}) ⇒ Object
Returns the conversations in the trash of messageable
Same as conversations(=> ‘trash’)
67 68 69 70 |
# File 'app/models/mailbox.rb', line 67 def trash(={}) = .merge(:mailbox_type => 'trash') return self.conversations() end |