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_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
94 95 96 |
# File 'app/models/conversation.rb', line 94 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
111 112 113 114 |
# File 'app/models/conversation.rb', line 111 def is_completely_trashed?(participant) return false if participant.nil? return self.receipts_for(participant).trash.count==self.receipts(participant).count end |
#is_participant?(participant) ⇒ Boolean
Returns true if the messageable is a participant of the conversation
99 100 101 102 |
# File 'app/models/conversation.rb', line 99 def is_participant?(participant) return false if participant.nil? return self.receipts_for(participant).count != 0 end |
#is_trashed?(participant) ⇒ Boolean
Returns true if the participant has at least one trashed message of the conversation
105 106 107 108 |
# File 'app/models/conversation.rb', line 105 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
117 118 119 120 |
# File 'app/models/conversation.rb', line 117 def is_unread?(participant) return false if participant.nil? return self.receipts_for(participant).unread.count!=0 end |
#last_message ⇒ Object
Last message in the conversation.
83 84 85 86 |
# File 'app/models/conversation.rb', line 83 def @last_message = self..find(:first, :order => 'created_at DESC') if @last_message.nil? return @last_message end |
#last_sender ⇒ Object
Sender of the last message.
77 78 79 80 |
# File 'app/models/conversation.rb', line 77 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
26 27 28 29 |
# File 'app/models/conversation.rb', line 26 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
32 33 34 35 |
# File 'app/models/conversation.rb', line 32 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
38 39 40 41 |
# File 'app/models/conversation.rb', line 38 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.
71 72 73 74 |
# File 'app/models/conversation.rb', line 71 def @original_message = self..find(:first, :order => 'created_at') if @original_message.nil? return @original_message end |
#originator ⇒ Object
Originator of the conversation.
65 66 67 68 |
# File 'app/models/conversation.rb', line 65 def originator @orignator = self..sender if @originator.nil? return @orignator end |
#participants ⇒ Object
Returns an array of participants
60 61 62 |
# File 'app/models/conversation.rb', line 60 def participants return recipients end |
#receipts_for(participant) ⇒ Object
Returns the receipts of the conversation for one participants
89 90 91 |
# File 'app/models/conversation.rb', line 89 def receipts_for(participant) return Receipt.conversation(self).recipient(participant) end |
#recipients ⇒ Object
Returns an array of participants
50 51 52 53 54 55 56 57 |
# File 'app/models/conversation.rb', line 50 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
44 45 46 47 |
# File 'app/models/conversation.rb', line 44 def untrash(participant) return if participant.nil? return self.receipts_for(participant).untrash end |