@@ -307,16 +307,28 @@ class SessionListViewModel(private val container: AppContainer) : ViewModel() {
307 _switchingId.value = null
307 _switchingId.value = null
308 result.onSuccess { refresh() }
308 result.onSuccess { refresh() }
309 .onFailure { error ->
309 .onFailure { error ->
310− // connect() already closed the old connection; if we just disconnect()
310+ // connect() already closed the old connection; try to restore the
311− // the user is left with nothing. Try to restore the previous profile so
312− // the session list survives. If there was none, show the error state.
311+ // previous profile so the session list survives. If there was none,
312+ // show the error state.
313 container.disconnect()
313 container.disconnect()
314 if (previousProfile != null) {
314 if (previousProfile != null) {
315− runCatchingCancellable { container.connect(previousProfile) }
315+ val restored = runCatchingCancellable { container.connect(previousProfile) }
316 // connect() clears unread state; restore what we saved so the
316 // connect() clears unread state; restore what we saved so the
317 // user doesn't lose unread badges on a failed server switch.
317 // user doesn't lose unread badges on a failed server switch.
318 savedUnread.forEach { container.restoreUnread(it) }
318 savedUnread.forEach { container.restoreUnread(it) }
319+ if (restored.isSuccess) {
319− _state.update { it.copy(loading = false, error = container.friendlyError(error)) }
320+ _state.update { it.copy(loading = false, error = container.friendlyError(error)) }
322+ // Restore also failed — the user is now disconnected from
323+ // both servers. Surface both failures so the user understands
324+ // why they're looking at an empty list.
325+ val restoreMsg = container.friendlyError(restored.exceptionOrNull() ?: error)
326+ _state.value = SessionListState(
328+ error = container.string(R.string.error_switch_and_restore_failed,
329+ container.friendlyError(error), restoreMsg),
321 _state.value = SessionListState(loading = false, error = container.friendlyError(error))
333 _state.value = SessionListState(loading = false, error = container.friendlyError(error))