Class: Mailboxer::Conversation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mailboxer::Conversation
- Defined in:
- app/models/mailboxer/conversation.rb,
app/models/mailboxer/conversation/opt_out.rb
Defined Under Namespace
Classes: OptOut
Instance Method Summary collapse
-
#add_participant(participant) ⇒ Object
Adds a new participant to the conversation.
-
#count_messages ⇒ Object
Returns the number of messages of the conversation.
-
#has_subscriber?(participant) ⇒ Boolean
tells if participant is opt in.
-
#is_completely_trashed?(participant) ⇒ Boolean
Returns true if the participant has trashed all the messages of the conversation.
-
#is_deleted?(participant) ⇒ Boolean
Returns true if the participant has deleted the conversation.
-
#is_orphaned? ⇒ Boolean
Returns true if both participants have deleted the conversation.
-
#is_participant?(participant) ⇒ Boolean
Returns true if the messageable is a participant of the conversation.
- #is_read?(participant) ⇒ Boolean
-
#is_trashed?(participant) ⇒ Boolean
Returns true if the participant has at least one trashed message of the conversation.
-
#is_unread?(participant) ⇒ Boolean
Returns true if the participant has at least one unread message of the conversation.
-
#last_message ⇒ Object
Last message in the conversation.
-
#last_sender ⇒ Object
Sender of the last message.
-
#mark_as_deleted(participant) ⇒ Object
Mark the conversation as deleted for one of the participants.
-
#mark_as_read(participant) ⇒ Object
Mark the conversation as read for one of the participants.
-
#mark_as_unread(participant) ⇒ Object
Mark the conversation as unread for one of the participants.
-
#move_to_trash(participant) ⇒ Object
Move the conversation to the trash for one of the participants.
-
#opt_in(participant) ⇒ Object
Destroys opt out object if any a participant outside of the discussion is, yet, not meant to optin.
-
#opt_out(participant) ⇒ Object
Creates a opt out object because by default all particpants are opt in.
-
#original_message ⇒ Object
First message of the conversation.
-
#originator ⇒ Object
Originator of the conversation.
-
#participants ⇒ Object
Returns an array of participants.
-
#receipts_for(participant) ⇒ Object
Returns the receipts of the conversation for one participants.
-
#recipients ⇒ Object
Returns an array of participants.
-
#untrash(participant) ⇒ Object
Takes the conversation out of the trash for one of the participants.
Instance Method Details
#add_participant(participant) ⇒ Object
Adds a new participant to the conversation
119 120 121 122 123 124 125 126 127 128 |
# File 'app/models/mailboxer/conversation.rb', line 119 def add_participant(participant) .each do || Mailboxer::ReceiptBuilder.new({ :notification => , :receiver => participant, :updated_at => .updated_at, :created_at => .created_at }).build.save end end |
#count_messages ⇒ Object
Returns the number of messages of the conversation
108 109 110 |
# File 'app/models/mailboxer/conversation.rb', line 108 def Mailboxer::Message.conversation(self).count end |
#has_subscriber?(participant) ⇒ Boolean
tells if participant is opt in
179 180 181 |
# File 'app/models/mailboxer/conversation.rb', line 179 def has_subscriber?(participant) !opt_outs.unsubscriber(participant).any? end |
#is_completely_trashed?(participant) ⇒ Boolean
Returns true if the participant has trashed all the messages of the conversation
150 151 152 153 |
# File 'app/models/mailboxer/conversation.rb', line 150 def is_completely_trashed?(participant) return false unless participant receipts_for(participant).trash.count == receipts_for(participant).count end |
#is_deleted?(participant) ⇒ Boolean
Returns true if the participant has deleted the conversation
137 138 139 140 |
# File 'app/models/mailboxer/conversation.rb', line 137 def is_deleted?(participant) return false unless participant return receipts_for(participant).deleted.count == receipts_for(participant).count end |
#is_orphaned? ⇒ Boolean
Returns true if both participants have deleted the conversation
143 144 145 146 147 |
# File 'app/models/mailboxer/conversation.rb', line 143 def is_orphaned? participants.reduce(true) do |is_orphaned, participant| is_orphaned && is_deleted?(participant) end end |
#is_participant?(participant) ⇒ Boolean
Returns true if the messageable is a participant of the conversation
113 114 115 116 |
# File 'app/models/mailboxer/conversation.rb', line 113 def is_participant?(participant) return false unless participant receipts_for(participant).any? end |
#is_read?(participant) ⇒ Boolean
155 156 157 |
# File 'app/models/mailboxer/conversation.rb', line 155 def is_read?(participant) !is_unread?(participant) end |
#is_trashed?(participant) ⇒ Boolean
Returns true if the participant has at least one trashed message of the conversation
131 132 133 134 |
# File 'app/models/mailboxer/conversation.rb', line 131 def is_trashed?(participant) return false unless participant receipts_for(participant).trash.count != 0 end |
#is_unread?(participant) ⇒ Boolean
Returns true if the participant has at least one unread message of the conversation
160 161 162 163 |
# File 'app/models/mailboxer/conversation.rb', line 160 def is_unread?(participant) return false unless participant receipts_for(participant).not_trash.is_unread.count != 0 end |
#last_message ⇒ Object
Last message in the conversation.
98 99 100 |
# File 'app/models/mailboxer/conversation.rb', line 98 def @last_message ||= .order('created_at DESC').first end |
#last_sender ⇒ Object
Sender of the last message.
93 94 95 |
# File 'app/models/mailboxer/conversation.rb', line 93 def last_sender @last_sender ||= .sender end |
#mark_as_deleted(participant) ⇒ Object
Mark the conversation as deleted for one of the participants
61 62 63 64 65 66 67 68 69 |
# File 'app/models/mailboxer/conversation.rb', line 61 def mark_as_deleted(participant) return unless participant deleted_receipts = receipts_for(participant).mark_as_deleted if is_orphaned? destroy else deleted_receipts end end |
#mark_as_read(participant) ⇒ Object
Mark the conversation as read for one of the participants
37 38 39 40 |
# File 'app/models/mailboxer/conversation.rb', line 37 def mark_as_read(participant) return unless participant receipts_for(participant).mark_as_read end |
#mark_as_unread(participant) ⇒ Object
Mark the conversation as unread for one of the participants
43 44 45 46 |
# File 'app/models/mailboxer/conversation.rb', line 43 def mark_as_unread(participant) return unless participant receipts_for(participant).mark_as_unread end |
#move_to_trash(participant) ⇒ Object
Move the conversation to the trash for one of the participants
49 50 51 52 |
# File 'app/models/mailboxer/conversation.rb', line 49 def move_to_trash(participant) return unless participant receipts_for(participant).move_to_trash end |
#opt_in(participant) ⇒ Object
Destroys opt out object if any a participant outside of the discussion is, yet, not meant to optin
174 175 176 |
# File 'app/models/mailboxer/conversation.rb', line 174 def opt_in(participant) opt_outs.unsubscriber(participant).destroy_all end |
#opt_out(participant) ⇒ Object
Creates a opt out object because by default all particpants are opt in
167 168 169 170 |
# File 'app/models/mailboxer/conversation.rb', line 167 def opt_out(participant) return unless has_subscriber?(participant) opt_outs.create(:unsubscriber => participant) end |
#original_message ⇒ Object
First message of the conversation.
88 89 90 |
# File 'app/models/mailboxer/conversation.rb', line 88 def @original_message ||= .order('created_at').first end |
#originator ⇒ Object
Originator of the conversation.
83 84 85 |
# File 'app/models/mailboxer/conversation.rb', line 83 def originator @originator ||= .sender end |
#participants ⇒ Object
Returns an array of participants
78 79 80 |
# File 'app/models/mailboxer/conversation.rb', line 78 def participants recipients end |
#receipts_for(participant) ⇒ Object
Returns the receipts of the conversation for one participants
103 104 105 |
# File 'app/models/mailboxer/conversation.rb', line 103 def receipts_for(participant) Mailboxer::Receipt.conversation(self).recipient(participant) end |
#recipients ⇒ Object
Returns an array of participants
72 73 74 75 |
# File 'app/models/mailboxer/conversation.rb', line 72 def recipients return [] unless Array .recipients end |
#untrash(participant) ⇒ Object
Takes the conversation out of the trash for one of the participants
55 56 57 58 |
# File 'app/models/mailboxer/conversation.rb', line 55 def untrash(participant) return unless participant receipts_for(participant).untrash end |