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
6 7 8 |
# File 'app/models/mailbox.rb', line 6 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/mailbox.rb', line 33 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) when 'not_trash' conv = Conversation.not_trash(@messageable) end end if (.has_key?(:read) && [:read]==false) || (.has_key?(:unread) && [:unread]==true) conv = conv.unread(@messageable) end conv end |
#empty_trash(options = {}) ⇒ Object
Deletes all the messages in the trash of messageable. NOT IMPLEMENTED.
86 87 88 89 |
# File 'app/models/mailbox.rb', line 86 def empty_trash( = {}) #TODO false end |
#has_conversation?(conversation) ⇒ Boolean
Returns if messageable is a participant of conversation
92 93 94 |
# File 'app/models/mailbox.rb', line 92 def has_conversation?(conversation) conversation.is_participant?(@messageable) end |
#inbox(options = {}) ⇒ Object
Returns the conversations in the inbox of messageable
Same as conversations(=> ‘inbox’)
59 60 61 62 |
# File 'app/models/mailbox.rb', line 59 def inbox(={}) = .merge(:mailbox_type => 'inbox') self.conversations() end |
#is_completely_trashed?(conversation) ⇒ Boolean
Returns true if messageable has trashed all the messages of the conversation
102 103 104 |
# File 'app/models/mailbox.rb', line 102 def is_completely_trashed?(conversation) conversation.is_completely_trashed?(@messageable) end |
#is_trashed?(conversation) ⇒ Boolean
Returns true if messageable has at least one trashed message of the conversation
97 98 99 |
# File 'app/models/mailbox.rb', line 97 def is_trashed?(conversation) conversation.is_trashed?(@messageable) end |
#notifications(options = {}) ⇒ Object
Returns the notifications for the messageable
11 12 13 14 15 16 17 18 19 |
# File 'app/models/mailbox.rb', line 11 def notifications( = {}) #:type => nil is a hack not to give Messages as Notifications notifs = Message.recipient(@messageable).order("messages.created_at DESC") if ([:read].present? and [:read]==false) or ([:unread].present? and [:unread]==true) notifs = notifs.unread end notifs end |
#receipts(options = {}) ⇒ Object
Returns all the receipts of messageable, from Messages and Notifications
81 82 83 |
# File 'app/models/mailbox.rb', line 81 def receipts( = {}) 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
114 115 116 117 118 119 120 121 |
# File 'app/models/mailbox.rb', line 114 def receipts_for(object) case object when Message#, Notification object.receipt_for(@messageable) when Conversation object.receipts_for(@messageable) end end |
#sentbox(options = {}) ⇒ Object
Returns the conversations in the sentbox of messageable
Same as conversations(=> ‘sentbox’)
67 68 69 70 |
# File 'app/models/mailbox.rb', line 67 def sentbox(={}) = .merge(:mailbox_type => 'sentbox') self.conversations() end |
#trash(options = {}) ⇒ Object
Returns the conversations in the trash of messageable
Same as conversations(=> ‘trash’)
75 76 77 78 |
# File 'app/models/mailbox.rb', line 75 def trash(={}) = .merge(:mailbox_type => 'trash') self.conversations() end |