extract some logic to chatroom