Class: Conversation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Conversation
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/models/conversation.rb
Instance Method Summary collapse
-
#count_messages ⇒ Object
Returns the number of messages of the conversation.
-
#is_completely_trashed?(participant) ⇒ Boolean
Returns true if the participant has trashed all the messages of 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_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.
-
#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
#count_messages ⇒ Object
Returns the number of messages of the conversation
102 103 104 |
# File 'app/models/conversation.rb', line 102 def return Message.conversation(self).count end |
#is_completely_trashed?(participant) ⇒ Boolean
Returns true if the participant has trashed all the messages of the conversation
119 120 121 122 |
# File 'app/models/conversation.rb', line 119 def is_completely_trashed?(participant) return false if participant.nil? return self.receipts_for(participant).trash.count == self.receipts_for(participant).count end |
#is_participant?(participant) ⇒ Boolean
Returns true if the messageable is a participant of the conversation
107 108 109 110 |
# File 'app/models/conversation.rb', line 107 def is_participant?(participant) return false if participant.nil? return self.receipts_for(participant).count != 0 end |
#is_read?(participant) ⇒ Boolean
124 125 126 |
# File 'app/models/conversation.rb', line 124 def is_read?(participant) !self.is_unread?(participant) end |
#is_trashed?(participant) ⇒ Boolean
Returns true if the participant has at least one trashed message of the conversation
113 114 115 116 |
# File 'app/models/conversation.rb', line 113 def is_trashed?(participant) return false if participant.nil? return self.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
129 130 131 132 |
# File 'app/models/conversation.rb', line 129 def is_unread?(participant) return false if participant.nil? return self.receipts_for(participant).not_trash.is_unread.count!=0 end |
#last_message ⇒ Object
Last message in the conversation.
91 92 93 94 |
# File 'app/models/conversation.rb', line 91 def @last_message = self..order('created_at DESC').first if @last_message.nil? return @last_message end |
#last_sender ⇒ Object
Sender of the last message.
85 86 87 88 |
# File 'app/models/conversation.rb', line 85 def last_sender @last_sender = self..sender if @last_sender.nil? return @last_sender end |
#mark_as_read(participant) ⇒ Object
Mark the conversation as read for one of the participants
34 35 36 37 |
# File 'app/models/conversation.rb', line 34 def mark_as_read(participant) return if participant.nil? return self.receipts_for(participant).mark_as_read end |
#mark_as_unread(participant) ⇒ Object
Mark the conversation as unread for one of the participants
40 41 42 43 |
# File 'app/models/conversation.rb', line 40 def mark_as_unread(participant) return if participant.nil? return self.receipts_for(participant).mark_as_unread end |
#move_to_trash(participant) ⇒ Object
Move the conversation to the trash for one of the participants
46 47 48 49 |
# File 'app/models/conversation.rb', line 46 def move_to_trash(participant) return if participant.nil? return self.receipts_for(participant).move_to_trash end |
#original_message ⇒ Object
First message of the conversation.
79 80 81 82 |
# File 'app/models/conversation.rb', line 79 def @original_message = self..order('created_at').first if @original_message.nil? return @original_message end |
#originator ⇒ Object
Originator of the conversation.
73 74 75 76 |
# File 'app/models/conversation.rb', line 73 def originator @originator = self..sender if @originator.nil? return @originator end |
#participants ⇒ Object
Returns an array of participants
68 69 70 |
# File 'app/models/conversation.rb', line 68 def participants return recipients end |
#receipts_for(participant) ⇒ Object
Returns the receipts of the conversation for one participants
97 98 99 |
# File 'app/models/conversation.rb', line 97 def receipts_for(participant) return Receipt.conversation(self).recipient(participant) end |
#recipients ⇒ Object
Returns an array of participants
58 59 60 61 62 63 64 65 |
# File 'app/models/conversation.rb', line 58 def recipients if self. recps = self..recipients recps = recps.is_a?(Array) ? recps : [recps] return recps end return [] end |
#untrash(participant) ⇒ Object
Takes the conversation out of the trash for one of the participants
52 53 54 55 |
# File 'app/models/conversation.rb', line 52 def untrash(participant) return if participant.nil? return self.receipts_for(participant).untrash end |