Commit 77d418cb authored by Janne Koschinski's avatar Janne Koschinski

Fixes #204

parent 2c8fdf3d
......@@ -449,7 +449,7 @@ class QuasselService : DaggerLifecycleService(),
private var backoff = BACKOFF_MIN
private var scheduled = false
private fun scheduleReconnect() {
if (!scheduled) {
if (!scheduled && sessionManager.canAutoReconnect(ignoreSetting = true)) {
log(INFO, "QuasselService", "Reconnect: Scheduling backoff in ${backoff / 1_000} seconds")
scheduled = true
handlerService.backendDelayed(backoff) {
......
......@@ -45,6 +45,7 @@ class SessionManager(
// Stateful fields
private var lastConnectionInfo: ConnectionInfo? = null
private var hasErrored: Boolean = false
private var hasBeenDisconnected: Boolean = false
private val disposables = mutableListOf<Disposable>()
......@@ -117,19 +118,24 @@ class SessionManager(
hasErrored = true
}
fun autoConnect(
fun canAutoReconnect(
ignoreConnectionState: Boolean = false,
ignoreSetting: Boolean = false,
ignoreErrors: Boolean = false,
connectionInfo: ConnectionInfo? = lastConnectionInfo
): Boolean {
if (hasBeenDisconnected) {
log(DEBUG, "SessionManager", "Reconnect not possible: manually disconnected")
return false
}
if (connectionInfo == null) {
log(INFO, "SessionManager", "Reconnect failed: not enough data available")
log(DEBUG, "SessionManager", "Reconnect not possible: not enough data available")
return false
}
if (!connectionInfo.shouldReconnect && !ignoreSetting) {
log(INFO, "SessionManager", "Reconnect failed: reconnect not allowed")
log(DEBUG, "SessionManager", "Reconnect not possible: reconnect not allowed")
return false
}
......@@ -137,21 +143,34 @@ class SessionManager(
if (connectionState != ConnectionState.DISCONNECTED &&
connectionState != ConnectionState.CLOSED &&
!ignoreConnectionState) {
log(INFO, "SessionManager", "Reconnect failed: connection state is $connectionState")
log(DEBUG, "SessionManager", "Reconnect not possible: connection state is $connectionState")
return false
}
if (hasErrored && !ignoreErrors) {
log(INFO, "SessionManager", "Reconnect failed: errors have been thrown")
log(DEBUG, "SessionManager", "Reconnect not possible: errors have been thrown")
return false
}
log(INFO, "SessionManager", "Reconnect successful")
connect(connectionInfo)
return true
}
fun autoConnect(
ignoreConnectionState: Boolean = false,
ignoreSetting: Boolean = false,
ignoreErrors: Boolean = false,
connectionInfo: ConnectionInfo? = lastConnectionInfo
): Boolean {
if (!canAutoReconnect(ignoreConnectionState, ignoreSetting, ignoreErrors, connectionInfo))
return false
log(DEBUG, "SessionManager", "Reconnect successful")
connect(connectionInfo!!)
return true
}
fun disconnect(forever: Boolean) {
hasBeenDisconnected = true
if (forever) backlogStorage.clearMessages()
updateStateOffline()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment