// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Layouts import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.components as Components import org.kde.kirigamiaddons.formcard as FormCard import koutnet.app // A group messenger would put a member list here. A direct-connection messenger has // one member and something more interesting to say about them: which key they proved // they hold, whether the TLS channel is really up, and which addresses their // packets came from - all three verified here rather than claimed by the peer. Kirigami.ScrollablePage { id: root // The page is one of the surfaces the theme's tone is painted on: with a // wallpaper behind the window, this is what stands between it and the // conversation, and a scheme grey here is the grey the theme was picked to // get rid of. A plain Rectangle for the same reason ChatPage has one - Kirigami // draws a gradient behind a page, and a gradient over a photograph is a // second wash on top of the scrim. background: Rectangle { color: ThemePalette.surface } // the map Main.qml builds: { ip, username, displayName, bio, os, e2e, // avatarLetter, isFavorites, online, lastSeen }. property var peer: null property bool encryptionExpanded: true property bool systemExpanded: true // Folded away to begin with: the addresses are the one thing here that says // where somebody is, and that should take a deliberate click. property bool addressExpanded: false property bool aboutExpanded: true signal profileRequested() readonly property string peerIp: root.peer ? (root.peer.ip || "") : "" readonly property string shownName: root.peer ? (root.peer.displayName && root.peer.displayName.length > 0 ? root.peer.displayName : (root.peer.username || i18nc("@info a peer that has published no name of its own", "Unknown peer"))) : "" // Function calls into the network engine rather than properties, so nothing // notifies on its own and refresh() stands in for that. The fingerprint is // the TLS pin: the key the peer proved in the handshake, not one it claims. property string fingerprint: "" property string peerIdentity: "" property bool encrypted: false property var addresses: [] title: i18nc("@title:window information about the peer on the other end", "Peer details") // See Main.qml: a ScrollablePage starts a theme chain of its own. function refresh() { if (root.peerIp.length === 0) { root.fingerprint = "" root.peerIdentity = "" root.encrypted = false root.addresses = [] return } root.fingerprint = networkManager.fingerprintForAddress(root.peerIp) root.encrypted = networkManager.hasTlsPeerByAddress(root.peerIp) const identity = networkManager.peerIdForAddress(root.peerIp) root.peerIdentity = identity root.addresses = identity.length > 0 ? networkManager.addressesForPeer(identity) : [] } onPeerChanged: root.refresh() Component.onCompleted: root.refresh() Connections { target: networkManager function onUserOnline(peerInfo) { if (peerInfo.ip === root.peerIp) root.refresh() } } Connections { target: networkManager function onTlsPeerAuthenticated(peerId, address) { if (address === root.peerIp) root.refresh() } // An avatar frame is the one way this page's face changes while it is // open: swap the map for a fresh copy so every binding that reads // root.peer re-evaluates (a plain-string property write against the // {ip: ...: avatar} map would not). function onPeerAvatar(ip, avatarSource) { if (ip === root.peerIp && root.peer) { // a fresh map so every binding that reads root.peer re-evaluates // (a plain property write into the existing map would not). root.peer = { ip: root.peer.ip, username: root.peer.username || "", displayName: root.peer.displayName || "", bio: root.peer.bio || "", os: root.peer.os || "", e2e: root.peer.e2e === true, avatarLetter: root.peer.avatarLetter || "", avatar: avatarSource, isFavorites: root.peer.isFavorites === true, online: root.peer.online === true, lastSeen: root.peer.lastSeen || 0, statusEmoji: root.peer.statusEmoji || "", presence: root.peer.presence || 0 } } } } ColumnLayout { spacing: 0 // not a banner: this column is fifteen grid units wide at its narrowest. ColumnLayout { Layout.fillWidth: true Layout.topMargin: Kirigami.Units.largeSpacing Layout.leftMargin: Kirigami.Units.largeSpacing Layout.rightMargin: Kirigami.Units.largeSpacing spacing: Kirigami.Units.smallSpacing Components.Avatar { Layout.alignment: Qt.AlignHCenter implicitWidth: Kirigami.Units.gridUnit * 5 implicitHeight: Kirigami.Units.gridUnit * 5 name: root.shownName // the face this peer pushed over the TLS channel; initials stand // in until an avatar frame has arrived. source: root.peer ? (root.peer.avatar || "") : "" } Kirigami.Heading { Layout.fillWidth: true level: 3 text: root.shownName textFormat: Text.PlainText elide: Text.ElideRight horizontalAlignment: Text.AlignHCenter } QQC2.Label { Layout.fillWidth: true visible: root.peer && root.peer.username && root.peer.username.length > 0 text: root.peer ? i18nc("@info a peer's handle, %1 is the user name", "@%1", (root.peer.username || "").replace(/^@/, "")) : "" textFormat: Text.PlainText elide: Text.ElideRight horizontalAlignment: Text.AlignHCenter color: AppPalette.disabledText } // RelativeTime.now is read so this ages with the column open. QQC2.Label { Layout.fillWidth: true text: root.peer ? RelativeTime.presenceLabel(root.peer.online === true, root.peer.lastSeen || 0, RelativeTime.now) : "" textFormat: Text.PlainText horizontalAlignment: Text.AlignHCenter font: Kirigami.Theme.smallFont color: (root.peer && root.peer.online === true) ? AppPalette.positiveText : AppPalette.disabledText } QQC2.Button { Layout.alignment: Qt.AlignHCenter Layout.topMargin: Kirigami.Units.smallSpacing text: i18nc("@action:button open the peer's full profile page", "Open profile") icon.name: "user-identity" onClicked: root.profileRequested() } } ChatSection { Layout.fillWidth: true text: i18nc("@title:group whether this conversation is encrypted", "Encryption") expanded: root.encryptionExpanded onToggleRequested: root.encryptionExpanded = !root.encryptionExpanded } ThemedFormCard { Layout.fillWidth: true visible: root.encryptionExpanded FormCard.FormTextDelegate { id: sessionDelegate icon.name: root.encrypted ? "security-high" : "security-low" text: root.encrypted ? i18nc("@info:status the session with this peer is end to end encrypted", "End to end encrypted") : i18nc("@info:status no pinned tls channel has been established with this peer", "Not encrypted") description: root.encrypted ? i18nc("@info:whatsthis", "A TLS channel with this peer succeeded and its key is pinned. Messages and calls ride that channel, protected by TLS 1.3.") : i18nc("@info:whatsthis", "No pinned TLS channel to this peer is up yet, so nothing sent to it is protected.") } FormCard.FormDelegateSeparator { above: sessionDelegate; below: fingerprintDelegate } // Reduced to something two people can read to each other: comparing it // out of band is the only thing that turns trust-on-first-use into trust. FormCard.AbstractFormDelegate { id: fingerprintDelegate Layout.fillWidth: true background: null focusPolicy: Qt.NoFocus contentItem: ColumnLayout { spacing: 0 QQC2.Label { Layout.fillWidth: true text: i18nc("@label the peer's identity fingerprint", "Identity fingerprint") textFormat: Text.PlainText elide: Text.ElideRight } Kirigami.SelectableLabel { Layout.fillWidth: true text: root.fingerprint.length > 0 && root.fingerprint !== "?" ? root.fingerprint : i18nc("@info the peer has never proved which key it holds", "Not established") // Fixed pitch so the groups line up against the other copy. font.family: "monospace" wrapMode: Text.WrapAnywhere color: root.fingerprint.length > 0 && root.fingerprint !== "?" ? ThemePalette.text : AppPalette.disabledText } } } FormCard.FormDelegateSeparator { above: fingerprintDelegate; below: resetTrustDelegate } FormCard.FormButtonDelegate { id: resetTrustDelegate icon.name: "edit-clear-history" text: i18nc("@action:button forget the pinned TLS key for this peer", "Reset trusted key") description: i18nc("@info:whatsthis", "Use this only after verifying the peer's new key out of band. The next connection will be trusted on first use again.") enabled: root.peerIdentity.length > 0 onClicked: resetTrustDialog.open() } Kirigami.PromptDialog { id: resetTrustDialog title: i18nc("@title:window", "Reset trusted key") subtitle: i18nc("@info %1 is a peer identity id, %2 is a file path", "Forget the pinned key for %1?\n\nPin file: %2\n\nDo this only if you verified the new fingerprint out of band. After reset, reconnect to trust the new key on first use.", root.peerIdentity.length > 0 ? root.peerIdentity : root.peerIp, networkManager.trustPinFile()) standardButtons: Kirigami.Dialog.NoButton showCloseButton: true customFooterActions: [ Kirigami.Action { text: i18nc("@action:button", "Reset key") icon.name: "edit-clear-history" onTriggered: { if (root.peerIdentity.length > 0) networkManager.forgetTrustedPeer(root.peerIdentity) root.refresh() resetTrustDialog.close() } }, Kirigami.Action { text: i18nc("@action:button", "Cancel") icon.name: "dialog-cancel" onTriggered: resetTrustDialog.close() } ] } } ChatSection { Layout.fillWidth: true text: i18nc("@title:group what the peer is running", "System") expanded: root.systemExpanded onToggleRequested: root.systemExpanded = !root.systemExpanded } ThemedFormCard { Layout.fillWidth: true visible: root.systemExpanded FormCard.FormTextDelegate { icon.name: "computer" text: i18nc("@label the peer's operating system", "Operating system") description: (root.peer && root.peer.os && root.peer.os.length > 0) ? root.peer.os : i18nc("@info the peer did not say what it is running", "Not advertised") } } ChatSection { Layout.fillWidth: true text: i18nc("@title:group the network addresses this peer has answered on", "Addresses") itemCount: root.addresses.length expanded: root.addressExpanded onToggleRequested: root.addressExpanded = !root.addressExpanded } ThemedFormCard { Layout.fillWidth: true visible: root.addressExpanded FormCard.FormTextDelegate { visible: root.addresses.length === 0 icon.name: "network-disconnect" text: i18nc("@info no packet from this peer has been verified yet", "No verified address") description: i18nc("@info:whatsthis", "Addresses appear here once a signed packet has actually arrived from one. What a peer advertises about itself is not listed.") } Repeater { model: root.addresses delegate: FormCard.FormTextDelegate { required property int index required property string modelData icon.name: "network-wired" text: modelData // Newest first, so the top one is where a message will be sent. description: index === 0 ? i18nc("@info:whatsthis the address most recently heard from", "Last heard from here") : i18nc("@info:whatsthis an address this peer has used before", "Also seen here") } } } ChatSection { Layout.fillWidth: true text: i18nc("@title:group free-form text the peer wrote about itself", "About") expanded: root.aboutExpanded onToggleRequested: root.aboutExpanded = !root.aboutExpanded } ThemedFormCard { Layout.fillWidth: true visible: root.aboutExpanded FormCard.AbstractFormDelegate { id: bioDelegate Layout.fillWidth: true background: null focusPolicy: Qt.NoFocus readonly property bool hasBio: root.peer && root.peer.bio && root.peer.bio.length > 0 contentItem: Kirigami.SelectableLabel { text: bioDelegate.hasBio ? root.peer.bio : i18nc("@info the peer wrote nothing about itself", "No description") textFormat: bioDelegate.hasBio ? Text.MarkdownText : Text.PlainText wrapMode: Text.WordWrap color: bioDelegate.hasBio ? ThemePalette.text : AppPalette.disabledText } } } } }