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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/mailbox.rb', line 31 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 (.has_key?(:read) && [:read]==false) || (.has_key?(:unread) && [:unread]==true) conv = conv.unread(@messageable) end return conv end |
#empty_trash(options = {}) ⇒ Object
Deletes all the messages in the trash of messageable. NOT IMPLEMENTED.
82 83 84 85 |
# File 'app/models/mailbox.rb', line 82 def empty_trash( = {}) #TODO return false end |
#has_conversation?(conversation) ⇒ Boolean
Returns if messageable is a participant of conversation
88 89 90 |
# File 'app/models/mailbox.rb', line 88 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’)
55 56 57 58 |
# File 'app/models/mailbox.rb', line 55 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
98 99 100 |
# File 'app/models/mailbox.rb', line 98 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
93 94 95 |
# File 'app/models/mailbox.rb', line 93 def is_trashed?(conversation) return conversation.is_trashed?(@messageable) end |
#notifications(options = {}) ⇒ Object
Returns the notifications for the messageable
10 11 12 13 14 15 16 17 |
# File 'app/models/mailbox.rb', line 10 def notifications( = {}) #:type => nil is a hack not to give Messages as Notifications notifs = Notification.recipient(@messageable).where(:type => nil).order("notifications.created_at DESC") if ([:read].present? and [:read]==false) or ([:unread].present? and [:unread]==true) notifs = notifs.unread end return notifs end |
#receipts(options = {}) ⇒ Object
Returns all the receipts of messageable, from Messages and Notifications
77 78 79 |
# File 'app/models/mailbox.rb', line 77 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
110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/mailbox.rb', line 110 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’)
63 64 65 66 |
# File 'app/models/mailbox.rb', line 63 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’)
71 72 73 74 |
# File 'app/models/mailbox.rb', line 71 def trash(={}) = .merge(:mailbox_type => 'trash') return self.conversations() end |