Introduce NeoChatConnection

Previously, some functions that conceptually belong to the connection needed to be in the Controller, since we didn't have a place to put them.
This fixes that by extending the Connection class in a similar way as we extend the Room class.
This commit is contained in:
Tobias Fella
2023-08-29 17:13:08 +02:00
parent 9071cf827f
commit e15bec2295
15 changed files with 250 additions and 235 deletions

View File

@@ -37,7 +37,7 @@ QQC2.Dialog {
text: i18n("Sign out")
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
onClicked: {
Controller.logout(root.connection, true);
root.connection.logout(true);
root.close();
root.accepted();
}

View File

@@ -193,7 +193,7 @@ QQC2.ToolBar {
Layout.fillWidth: true
}
QQC2.Label {
text: (Controller.activeAccountLabel.length > 0 ? (Controller.activeAccountLabel + " ") : "") + Controller.activeConnection.localUser.id
text: (Controller.activeConnection.label.length > 0 ? (Controller.activeConnection.label + " ") : "") + Controller.activeConnection.localUser.id
font.pointSize: displayNameLabel.font.pointSize * 0.8
opacity: 0.7
textFormat: Text.PlainText

View File

@@ -16,7 +16,7 @@ import org.kde.neochat 1.0
Kirigami.ScrollablePage {
id: root
title: i18n("Edit Account")
property var connection
property NeoChatConnection connection
readonly property bool compact: width > Kirigami.Units.gridUnit * 30 ? 2 : 1
@@ -114,7 +114,7 @@ Kirigami.ScrollablePage {
MobileForm.FormTextFieldDelegate {
id: accountLabel
label: i18n("Label:")
text: root.connection ? Controller.activeAccountLabel : ""
text: root.connection ? root.connection.label : ""
}
MobileForm.FormDelegateSeparator {}
MobileForm.AbstractFormDelegate {
@@ -130,14 +130,14 @@ Kirigami.ScrollablePage {
Layout.bottomMargin: Kirigami.Units.smallSpacing
Layout.topMargin: Kirigami.Units.smallSpacing
onClicked: {
if (!Controller.setAvatar(root.connection, avatar.source)) {
if (!root.connection.setAvatar(avatar.source)) {
showPassiveNotification("The Avatar could not be set");
}
if (root.connection.localUser.displayName !== name.text) {
root.connection.localUser.rename(name.text);
}
if (Controller.activeAccountLabel !== accountLabel.text) {
Controller.activeAccountLabel = accountLabel.text;
if (root.connection.label !== accountLabel.text) {
root.connection.label = accountLabel.text;
}
}
}
@@ -201,7 +201,7 @@ Kirigami.ScrollablePage {
enabled: currentPassword.text.length > 0 && newPassword.text.length > 0 && confirmPassword.text.length > 0
onClicked: {
if (newPassword.text === confirmPassword.text) {
Controller.changePassword(root.connection, currentPassword.text, newPassword.text);
root.connection.changePassword(currentPassword.text, newPassword.text);
} else {
showPassiveNotification(i18n("Passwords do not match"));
}

View File

@@ -35,17 +35,19 @@ Kirigami.ScrollablePage {
Repeater {
model: AccountRegistry
delegate: MobileForm.AbstractFormDelegate {
id: accountDelegate
required property NeoChatConnection connection
Layout.fillWidth: true
onClicked: pageStack.layers.push("qrc:/AccountEditorPage.qml", {
connection: model.connection
connection: accountDelegate.connection
}, {
title: i18n("Account editor")
})
contentItem: RowLayout {
KirigamiComponents.Avatar {
name: model.connection.localUser.displayName
source: model.connection.localUser.avatarMediaId ? ("image://mxc/" + model.connection.localUser.avatarMediaId) : ""
name: accountDelegate.connection.localUser.displayName
source: accountDelegate.connection.localUser.avatarMediaId ? ("image://mxc/" + accountDelegate.connection.localUser.avatarMediaId) : ""
Layout.rightMargin: Kirigami.Units.largeSpacing
implicitWidth: Kirigami.Units.iconSizes.medium
@@ -58,7 +60,7 @@ Kirigami.ScrollablePage {
QQC2.Label {
Layout.fillWidth: true
text: model.connection.localUser.displayName
text: accountDelegate.connection.localUser.displayName
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.Wrap
@@ -68,7 +70,7 @@ Kirigami.ScrollablePage {
QQC2.Label {
Layout.fillWidth: true
text: model.connection.localUserId
text: accountDelegate.connection.localUserId
color: Kirigami.Theme.disabledTextColor
font: Kirigami.Theme.smallFont
elide: Text.ElideRight
@@ -78,7 +80,7 @@ Kirigami.ScrollablePage {
QQC2.ToolButton {
text: i18n("Logout")
icon.name: "im-kick-user"
onClicked: confirmLogoutDialogComponent.createObject(QQC2.ApplicationWindow.overlay).open()
onClicked: confirmLogoutDialogComponent.createObject(applicationWindow().overlay).open()
}
Component {