I am making an app similar to Chatroulette.
I am using Ruby on Rails, so I am looking to use "state machine".
What I am not sure how to do is make the state depend on the state of another model or another object of the same class.
For example, in my databases right now, I have a User
, Conversation
and Message
table. The user has many conversations and each conversation belongs to two other users, so it's "many to many". The User
would either be in one of three states: inactive
, talking
, or waiting
. When the user enters the state of waiting
, if there is another user in the waiting
state they enter the conversation state together. If not the user waits until a user enters the waiting
state. When one of the users ends the conversation the user either go into waiting
or inactive
state, depending on if they pressed "next partner" or stop talking. When this happens that conversation goes into the end state. So a conversation would have two states: active
and ended
.
Any suggestions on how this should be achieved would be awesome.