Seperate the chat-window logic from the application delegate

This makes the code nicer to maintain and modify.