Class: Conversation

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messages_waitingObject

Returns the value of attribute messages_waiting.



7
8
9
# File 'app/models/conversation.rb', line 7

def messages_waiting
  @messages_waiting
end

Class Method Details

.flushObject



9
10
11
12
13
14
15
16
17
18
# File 'app/models/conversation.rb', line 9

def self.flush
  # end user's part in a conversation if not heard from them in the last X minutes
  ConversationUser.connection.execute("delete from conversation_users where user_id not in (select id from users where last_heard_from > date_sub(now(), interval 1 minute))")

  # end the conversation if only one user remains
  Conversation.connection.execute("delete from conversations where id not in (select conversation_id from (select conversation_id, count(*) as cnt from conversation_users cu group by conversation_id) cu2 where cu2.cnt > 1 )")

  # clean out users from conversations that don't exist any longer
  Conversation.connection.execute("delete from conversation_users where conversation_id not in (select id from conversations)")
end

Instance Method Details



20
21
22
# File 'app/models/conversation.rb', line 20

def link
  "/convo/" + self.id.to_s
end