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
99 100 101 |
# File 'app/models/conversation.rb', line 99 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
116 117 118 119 |
# File 'app/models/conversation.rb', line 116 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
104 105 106 107 |
# File 'app/models/conversation.rb', line 104 def is_participant?(participant) return false if participant.nil? return self.receipts_for(participant).count != 0 end |
#is_read?(participant) ⇒ Boolean
121 122 123 |
# File 'app/models/conversation.rb', line 121 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
110 111 112 113 |
# File 'app/models/conversation.rb', line 110 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
126 127 128 129 |
# File 'app/models/conversation.rb', line 126 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.
88 89 90 91 |
# File 'app/models/conversation.rb', line 88 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.
82 83 84 85 |
# File 'app/models/conversation.rb', line 82 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
31 32 33 34 |
# File 'app/models/conversation.rb', line 31 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
37 38 39 40 |
# File 'app/models/conversation.rb', line 37 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
43 44 45 46 |
# File 'app/models/conversation.rb', line 43 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.
76 77 78 79 |
# File 'app/models/conversation.rb', line 76 def @original_message = self..find(:first, :order => 'created_at') if @original_message.nil? return @original_message end |
#originator ⇒ Object
Originator of the conversation.
70 71 72 73 |
# File 'app/models/conversation.rb', line 70 def originator @orignator = self..sender if @originator.nil? return @orignator end |
#participants ⇒ Object
Returns an array of participants
65 66 67 |
# File 'app/models/conversation.rb', line 65 def participants return recipients end |
#receipts_for(participant) ⇒ Object
Returns the receipts of the conversation for one participants
94 95 96 |
# File 'app/models/conversation.rb', line 94 def receipts_for(participant) return Receipt.conversation(self).recipient(participant) end |
#recipients ⇒ Object
Returns an array of participants
55 56 57 58 59 60 61 62 |
# File 'app/models/conversation.rb', line 55 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
49 50 51 52 |
# File 'app/models/conversation.rb', line 49 def untrash(participant) return if participant.nil? return self.receipts_for(participant).untrash end |