Fix notification order

Notify authentication listeners after the client to ensure messages are
correctly ordered.
Fix race conditions related to outstanding events

Check whether we are waiting for a login response to be processed by the
main thread before discarding chat messages.