Improve initial active connection handling

If the last active connection is not reachable (server down, keychain problems,
token revoked, etc.), NeoChat currently fails to load at all, with the only fix
being to delete a line from the config file. This is surprisingly hard to fix with
a nice UX as long as we stick to the principle of loading the user's last active
connection automatically.

This patch thus drops that principle; instead, the user is always asked to choose
the connection to continue with.
This commit is contained in:
Tobias Fella
2023-11-03 15:27:52 +01:00
parent c4f6abee9d
commit 7f9e709559
9 changed files with 83 additions and 32 deletions

View File

@@ -1,13 +0,0 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
Kirigami.Page {
title: i18n("Loading…")
Kirigami.LoadingPlaceholder {
id: loadingIndicator
anchors.centerIn: parent
}
}

View File

@@ -14,7 +14,12 @@ import org.kde.neochat.accounts
FormCard.FormCardPage {
id: root
property bool showExisting: false
property bool _showExisting: showExisting && module.source == root.initialStep
property alias currentStep: module.item
property string initialStep: "qrc:/org/kde/neochat/qml/LoginRegister.qml"
signal connectionChosen
title: i18n("Welcome")
@@ -42,17 +47,47 @@ FormCard.FormCardPage {
FormCard.FormTextDelegate {
id: welcomeMessage
text: AccountRegistry.accountCount > 0 ? i18n("Log in to a different account or create a new account.") : i18n("Welcome to NeoChat! Continue by logging in or creating a new account.")
text: i18n("Welcome to NeoChat")
}
}
FormCard.FormDelegateSeparator {
above: welcomeMessage
FormCard.FormHeader {
id: existingAccountsHeader
title: i18nc("@title", "Continue with an existing account")
visible: (loadedAccounts.count > 0 || loadingAccounts.count > 0) && root._showExisting
}
FormCard.FormCard {
visible: existingAccountsHeader.visible
Repeater {
id: loadedAccounts
model: AccountRegistry
delegate: FormCard.FormButtonDelegate {
text: model.userId
onClicked: {
Controller.activeConnection = model.connection
root.connectionChosen()
}
}
}
Repeater {
id: loadingAccounts
model: Controller.accountsLoading
delegate: FormCard.FormButtonDelegate {
text: i18nc("As in 'this account is still loading'", "%1 (loading)", modelData)
enabled: false
}
}
}
FormCard.FormHeader {
title: i18nc("@title", "Log in or Create a New Account")
}
FormCard.FormCard {
Loader {
id: module
Layout.fillWidth: true
source: "qrc:/org/kde/neochat/qml/LoginRegister.qml"
source: root.initialStep
Connections {
id: stepConnections

View File

@@ -31,7 +31,15 @@ Kirigami.ApplicationWindow {
wideScreen: width > columnWidth * 5
pageStack {
initialPage: LoadingPage {}
initialPage: WelcomePage {
showExisting: true
onConnectionChosen: {
pageStack.replace(roomListComponent);
roomListLoaded = true;
roomListPage = pageStack.currentItem
RoomManager.loadInitialRoom();
}
}
globalToolBar.canContainHandles: true
defaultColumnWidth: roomListPage ? roomListPage.currentWidth : 0
globalToolBar {
@@ -47,6 +55,16 @@ Kirigami.ApplicationWindow {
SpaceHierarchyCache.connection = root.connection
}
Connections {
target: LoginHelper
function onLoaded() {
pageStack.replace(roomListComponent);
roomListLoaded = true;
roomListPage = pageStack.currentItem
RoomManager.loadInitialRoom();
}
}
Connections {
target: root.quitAction
function onTriggered() {
@@ -279,17 +297,6 @@ Kirigami.ApplicationWindow {
Connections {
target: Controller
function onInitiated() {
if (AccountRegistry.accountCount === 0) {
pageStack.replace("qrc:/org/kde/neochat/qml/WelcomePage.qml", {});
} else if (!roomListLoaded) {
pageStack.replace(roomListComponent);
roomListLoaded = true;
roomListPage = pageStack.currentItem
RoomManager.loadInitialRoom();
}
}
function onGlobalErrorOccured(error, detail) {
showPassiveNotification(i18n("%1: %2", error, detail));
}