disconnectUser method
Closes the _ws
connection and resets the state
If flushChatPersistence
is true the client deletes all offline
user's data.
Implementation
Future<void> disconnectUser({bool flushChatPersistence = false}) async {
logger.info('Disconnecting user : ${state.currentUser?.id}');
// resetting state
state.dispose();
state = ClientState(this);
_lastSyncedAt = null;
// resetting credentials
_tokenManager.reset();
_connectionIdManager.reset();
// disconnecting persistence client
await _chatPersistenceClient?.disconnect(flush: flushChatPersistence);
_chatPersistenceClient = null;
// closing web-socket connection
closeConnection();
}