reset method
Forgets this visitor: the old token stops working, a fresh visitor is
bootstrapped and the push token (if any) is re-registered for it. Before
start (autoConnect: false, chat never opened) the stored visitor is
forgotten all the same, and the new one connects on the next start.
Implementation
Future<void> reset() async {
await _ensureLoaded();
final old = _token;
if (old == null) return;
final r = await _api.reset(token: old, installId: _installId);
final push = _stored.pushToken;
if (push != null) {
try {
await _api.deleteDevice(token: old, pushToken: push);
} on HatangException catch (e) {
_log.warn('device removal failed: $e');
}
}
_closeSocket();
_token = r.visitorToken;
_pushRegisteredFor = null;
_pushDirty = push != null;
await _persist(
StoredSession(
token: r.visitorToken,
locale: _stored.locale,
pushToken: _stored.pushToken,
pushProvider: _stored.pushProvider,
),
);
_emit(
ChatState(
phase: ChatPhase.bootstrapping,
connection: HatangConnectionState.connecting,
locale: _state.locale,
visible: _state.visible,
foreground: _state.foreground,
config: _state.config,
),
);
if (_started) await _bootstrapAndConnect();
_event(HatangSessionChanged(visitorId: r.visitorId, reason: HatangSessionChangeReason.reset));
}