Class: Conversation

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/models/conversation.rb

Instance Method Summary collapse

Instance Method Details

#count_messagesObject

Returns the number of messages of the conversation



94
95
96
# File 'app/models/conversation.rb', line 94

def count_messages
	return Message.conversation(self).count
end

#is_completely_trashed?(participant) ⇒ Boolean

Returns true if the participant has trashed all the messages of the conversation

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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_messageObject

Last message in the conversation.



83
84
85
86
# File 'app/models/conversation.rb', line 83

def last_message
	@last_message = self.messages.find(:first, :order => 'created_at DESC') if @last_message.nil?
	return @last_message
end

#last_senderObject

Sender of the last message.



77
78
79
80
# File 'app/models/conversation.rb', line 77

def last_sender
	@last_sender = self.last_message.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_messageObject

First message of the conversation.



71
72
73
74
# File 'app/models/conversation.rb', line 71

def original_message
	@original_message = self.messages.find(:first, :order => 'created_at') if @original_message.nil?
	return @original_message
end

#originatorObject

Originator of the conversation.



65
66
67
68
# File 'app/models/conversation.rb', line 65

def originator
	@orignator = self.original_message.sender if @originator.nil?
	return @orignator
end

#participantsObject

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

#recipientsObject

Returns an array of participants



50
51
52
53
54
55
56
57
# File 'app/models/conversation.rb', line 50

def recipients
	if self.last_message
		recps = self.last_message.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