// 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 org.kde.kirigamiaddons.delegates as Delegates import QtQuick.Dialogs as Dialogs import koutnet.app // PeerInfoPage's opposite number. That one answers "who is on the other end" - a // fingerprint, an OS, the addresses packets came from. A room has no other end, // so this answers what the room is for, what it is called, whether it is // encrypted and who is in it. The two pages share a shape so switching between // a room and a LAN chat does not feel like switching applications. Kirigami.ScrollablePage { id: root // the "mx:" chat id, not the bare room id. Everything is read back off this, so // switching conversation with the column open re-points it. property string chatId: "" // Folded away to begin with: the id and the aliases are the one thing here // that would be pasted somewhere, and that should take a deliberate click. signal memberActivated(string userId, Item anchorItem) signal leaveRequested(string chatId) signal notifyRequested(string text) // the dialog lives in the window, not the column: a verification outlives the // column and is about the account, not this room. signal verifySessionsRequested() // encryption is a state event with no way back, so it is asked for here and // confirmed where it is offered rather than done the moment it is clicked. signal encryptionRequested(string chatId) // Filled by refresh(). Function calls rather than properties on the bridge, // because a member list nobody is looking at should cost nothing. property var info: null property var members: [] // How much of the member list is drawn: a page at a time, with a button asking // for the next, since rooms are long and the interesting part is the top. readonly property int memberPageSize: 50 property int membersShownCount: root.memberPageSize readonly property var membersShown: root.members.slice(0, root.membersShownCount) // Pinned messages (from roomPinnedChanged) and search results, kept here so // the two sections below can list them without another bridge round trip. property var pinned: [] property var searchResults: [] readonly property string roomName: root.info ? (root.info.displayName || "") : "" readonly property string topic: root.info ? (root.info.topic || "") : "" readonly property string canonicalAlias: root.info ? (root.info.canonicalAlias || "") : "" readonly property var altAliases: root.info ? (root.info.altAliases || []) : [] readonly property string roomId: root.info ? (root.info.roomId || "") : "" readonly property bool encrypted: root.info ? root.info.encrypted === true : false // whether the session can do encryption, as opposed to whether the room wants // it: an encrypted room with no key store must not wear a padlock. readonly property bool encryptionActive: root.info ? root.info.encryptionActive === true : false // False when libQuotient's trust tables could not be asked: "nobody is verified" // and "nobody was asked" are different statements. readonly property bool trustKnown: root.info ? root.info.trustKnown === true : false readonly property bool ownSessionsVerified: root.info ? root.info.ownSessionsVerified === true : false readonly property bool keyBackupAvailable: root.info ? root.info.keyBackupAvailable === true : false readonly property bool keyBackupUnlocked: root.info ? root.info.keyBackupUnlocked === true : false // -1 when the room has not said, which is the answer before its state arrives: // the button is offered and the homeserver has the last word. readonly property int ownPowerLevel: root.info ? (root.info.ownPowerLevel !== undefined ? root.info.ownPowerLevel : -1) : -1 readonly property int joinedCount: root.info ? (root.info.joinedCount || 0) : 0 readonly property int invitedCount: root.info ? (root.info.invitedCount || 0) : 0 title: i18nc("@title:window the topic, address and members of a Matrix room", "Room information") // The ScrollView's own scrollbar is put away: the page attaches its own to the // flickable, and two scrollbars for one column is one too many. verticalScrollBarPolicy: QQC2.ScrollBar.AlwaysOff // What the scrollbar costs the page's right edge, so the cross over the panel // is held off it. The floor is the one the timeline uses. readonly property real scrollBarRoom: Math.max(Kirigami.Units.smallSpacing, sideScrollBar.implicitWidth) // See Main.qml: a ScrollablePage starts a theme chain of its own. // Copying the address is the one action the collapsed strip shares with the // page: the helper and the toast are the same ones either shape reaches. function copyAddress() { clipboardHelper.copyText(root.canonicalAlias.length > 0 ? root.canonicalAlias : root.roomId) root.notifyRequested(i18nc("@info:status", "Room address copied to the clipboard")) } function refresh() { if (root.chatId.length === 0) { root.info = null root.members = [] return } root.info = chatTransport.roomInfo(root.chatId) root.members = chatTransport.roomMembers(root.chatId) // a different room is a different list, so the pages of the old one do // not carry over into it. root.membersShownCount = root.memberPageSize } onChatIdChanged: root.refresh() Component.onCompleted: root.refresh() Connections { target: matrixRooms function onRoomInfoChanged(chatId) { if (chatId === root.chatId) root.refresh() } } // Unlocking the backup re-arms the restore button and flips its label, and // that state lives on the account rather than on this room. Connections { target: matrixManager function onKeyBackupUnlocked() { root.refresh() } } // the pinned set and search results are emitted by the bridge with the chat // id; re-point them when they are about this room. Connections { target: matrixRooms function onRoomPinnedChanged(chatId, list) { if (chatId === root.chatId) root.pinned = list } function onRoomSearchResults(chatId, list) { if (chatId === root.chatId) root.searchResults = list } } // same trick as ChatPage: there is no clipboard object in QML without a C++ // helper for it, and one off-screen editor is cheaper than the helper. TextEdit { id: clipboardHelper visible: false function copyText(str) { text = str selectAll() copy() } } actions: [ Kirigami.Action { text: i18nc("@action:button back to the conversation from the room information page", "Back") icon.name: "go-previous" // Room info lives on an overlay layer so it can be dismissed at any // width; pop the layer rather than the pageStack column. onTriggered: applicationWindow().pageStack.layers.pop() }, Kirigami.Action { text: i18nc("@action:button copy the room's address so it can be pasted elsewhere", "Copy address") icon.name: "edit-copy" visible: root.canonicalAlias.length > 0 || root.roomId.length > 0 onTriggered: root.copyAddress() }, Kirigami.Action { text: i18nc("@action:button leave a Matrix room", "Leave room") icon.name: "window-close" visible: root.roomId.length > 0 onTriggered: leaveConfirm.open() } ] // Asked about rather than done: rejoining an invite-only room is not this // window's to arrange. Kirigami.PromptDialog { id: leaveConfirm // See the note on Kirigami.Theme in Main.qml. Kirigami.Theme.inherit: false title: i18nc("@title:window", "Leave this room?") subtitle: i18nc("@info", "You will stop receiving messages from it. Getting back in may need a new invitation.") standardButtons: Kirigami.Dialog.Cancel customFooterActions: [ Kirigami.Action { text: i18nc("@action:button confirm leaving a Matrix room", "Leave") icon.name: "window-close" onTriggered: { root.leaveRequested(root.chatId) leaveConfirm.close() } } ] } // The column the page scrolls, inside a Flickable of the page's own: the thin // scrollbar attaches to a scroller this page declares, and ScrollablePage // adopts it - reparenting it and pointing the header and keys at it. Flickable { id: roomInfoScroller // the ScrollablePage clears these anchors when it adopts the flickable and // the ScrollView gives it the room; the size bindings are what survive. width: parent.width height: parent.height contentWidth: width contentHeight: roomInfoColumn.implicitHeight // The page's own scrollbar, half the style's column and drawn by hand for // the reasons the timeline's is (see MessageTimeline.qml). Attached inside // the flickable it scrolls, with the style's visible binding still deciding. QQC2.ScrollBar.vertical: QQC2.ScrollBar { id: sideScrollBar implicitWidth: Math.round(Kirigami.Units.gridUnit * 10 / 18) contentItem: Rectangle { implicitWidth: parent.width implicitHeight: parent.height radius: width / 2 color: sideScrollBar.pressed ? Kirigami.ColorUtils.linearInterpolation(ThemePalette.surface, ThemePalette.text, 0.5) : Kirigami.ColorUtils.linearInterpolation(ThemePalette.surface, ThemePalette.text, 0.35) opacity: sideScrollBar.active ? 0.85 : 0.55 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration easing.type: Easing.OutCubic } } } background: null } ColumnLayout { id: roomInfoColumn width: roomInfoScroller.width 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.roomName source: root.info ? (root.info.avatarUrl || "") : "" // the room's picture is one tap from a new one; the picker hands // the path to the bridge, which uploads and points the state at it. MouseArea { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: avatarDialog.open() } } Kirigami.Heading { Layout.fillWidth: true level: 3 text: root.roomName textFormat: Text.PlainText elide: Text.ElideRight horizontalAlignment: Text.AlignHCenter } QQC2.Label { Layout.fillWidth: true visible: root.canonicalAlias.length > 0 text: root.canonicalAlias textFormat: Text.PlainText elide: Text.ElideMiddle horizontalAlignment: Text.AlignHCenter color: AppPalette.disabledText } QQC2.Label { Layout.fillWidth: true // one string rather than two joined with a space: the order of // the two counts is a translator's to decide. text: root.invitedCount > 0 ? i18ncp("@info:status %1 is how many people are in the room, %2 how many have been invited and not joined", "%1 member, %2 invited", "%1 members, %2 invited", root.joinedCount, root.invitedCount) : i18ncp("@info:status %1 is how many people are in the room", "%1 member", "%1 members", root.joinedCount) textFormat: Text.PlainText horizontalAlignment: Text.AlignHCenter font: Kirigami.Theme.smallFont color: AppPalette.disabledText } } // The actions up top, after NeoChat's RoomInformation: one flat row each // rather than a section to unfold. Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group the things that can be done in this room", "Actions") } ThemedFormCard { Layout.fillWidth: true Layout.fillHeight: false // flat rows: no card padding around each one, so the list reads as // one block the way NeoChat's does Delegates.RoundedItemDelegate { Layout.fillWidth: true icon.name: "edit-find" text: i18nc("@action:button search the messages in this room", "Search messages") onClicked: { root.searchExpanded = true } } Delegates.RoundedItemDelegate { Layout.fillWidth: true icon.name: "view-pin" text: i18nc("@action:button read what is pinned in this room", "Pinned messages") onClicked: { root.pinnedExpanded = true } } Delegates.RoundedItemDelegate { Layout.fillWidth: true icon.name: "system-users-symbolic" text: i18nc("@action:button read who is in this room", "Members") onClicked: { root.membersExpanded = true } } } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group what a Matrix room is for", "Topic") } ThemedFormCard { Layout.fillWidth: true FormCard.AbstractFormDelegate { id: topicDelegate Layout.fillWidth: true background: null focusPolicy: Qt.NoFocus readonly property bool hasTopic: root.topic.length > 0 contentItem: Kirigami.SelectableLabel { text: topicDelegate.hasTopic ? root.topic : i18nc("@info the room has set no topic", "No topic set") // A topic is plain text in the protocol; rendering it as // anything else would let a room write markup into this column. textFormat: Text.PlainText wrapMode: Text.WordWrap color: topicDelegate.hasTopic ? ThemePalette.text : AppPalette.disabledText } } } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group whether this room is encrypted", "Encryption") } ThemedFormCard { Layout.fillWidth: true FormCard.FormTextDelegate { icon.name: !root.encrypted ? "security-low" : (root.encryptionActive ? "security-high" : "dialog-warning") text: !root.encrypted ? i18nc("@info:status the room is not encrypted", "Not encrypted") : (root.encryptionActive ? i18nc("@info:status the room is end to end encrypted", "End to end encrypted") : i18nc("@info:status the room is encrypted but this session has no keys", "Encrypted, and unreadable here")) description: !root.encrypted ? i18nc("@info:whatsthis", "Messages here are readable by the homeserver and by anybody it federates with.") : (root.encryptionActive ? i18nc("@info:whatsthis", "Messages here are encrypted for the devices in the room, so the homeserver stores them but cannot read them. Messages sent before this device joined stay unreadable, because their keys were never sent to it.") : i18nc("@info:whatsthis", "This session could not open its encryption keys, so nothing in this room can be read and nothing can be sent to it.")) } // Offered only where it can work. A session with no key store would // encrypt a room it can then never read, and a power level below // state_default would be refused anyway. FormCard.FormButtonDelegate { visible: !root.encrypted && root.encryptionActive && root.ownPowerLevel !== -1 icon.name: "security-high" text: i18nc("@action:button turn on end to end encryption for this room", "Turn on end to end encryption") description: i18nc("@info:whatsthis", "From now on only the devices in this room can read what is said here, and nothing said before this can be made private afterwards. This cannot be undone.") enabled: root.ownPowerLevel >= 50 onClicked: encryptionConfirmDialog.open() } // A second line, never folded into the first: encryption says the // homeserver cannot read the room; verification says whose devices can. FormCard.FormTextDelegate { visible: root.encrypted && root.encryptionActive icon.name: root.trustKnown && root.ownSessionsVerified ? "security-medium" : "security-low" text: !root.trustKnown ? i18nc("@info:status device verification could not be checked", "Verification unknown") : (root.ownSessionsVerified ? i18nc("@info:status all of this account's own sessions are verified", "Your other sessions are verified") : i18nc("@info:status some of this account's own sessions are unverified", "Some of your sessions are unverified")) description: !root.trustKnown ? i18nc("@info:whatsthis", "The trust table could not be read, so nothing here has been checked either way.") : (root.ownSessionsVerified ? i18nc("@info:whatsthis", "Every other session on this account has been verified from here, so they will share their room keys with this one.") : i18nc("@info:whatsthis", "An unverified session is refused keys by some clients, which is why parts of an encrypted room can stay unreadable. Verify this one against another session of yours to fix that.")) } // separate from the line above: that one reports, and goes on saying // the same thing whether or not there is anything to do. FormCard.FormButtonDelegate { visible: root.encrypted && root.encryptionActive && root.trustKnown icon.name: "security-medium" text: i18nc("@action:button open the device verification dialog", "Verify sessions...") description: i18nc("@info:whatsthis", "Compare emoji with another Matrix session of yours to prove this one is the same person.") onClicked: root.verifySessionsRequested() } // the room key backup answers "messages sent before this device joined // stay unreadable": an encrypted copy of the keys waits on the // homeserver. Offered once this session can use keys at all. FormCard.FormButtonDelegate { visible: root.encrypted && root.encryptionActive && root.keyBackupAvailable === true icon.name: "drive-removable-media" text: root.keyBackupUnlocked ? i18nc("@action:button the room key backup is already unlocked", "Room keys restored from backup") : i18nc("@action:button open the dialog that unlocks the room key backup", "Restore room keys from backup...") description: root.keyBackupUnlocked ? i18nc("@info:whatsthis", "The backup on the homeserver was already unlocked in this session, so messages from the past appear as their keys arrive.") : i18nc("@info:whatsthis", "Ask the homeserver for the encrypted copy of the room keys. A recovery key or the backup passphrase unlocks it; messages sent before this device joined become readable after this.") enabled: !root.keyBackupUnlocked onClicked: keyBackupDialog.open() } } KeyBackupDialog { id: keyBackupDialog } // Asked before it is sent, because no event can put the room back: the // message the homeserver can read is already sent. Kirigami.Dialog { id: encryptionConfirmDialog title: i18nc("@title:confirm turning on end to end encryption", "Turn on encryption?") modal: true standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel contentItem: Text { text: i18nc("@info:status what turning on encryption does to this room", "Messages sent in this room from now on will be readable only by the devices that are in it. Messages already sent stay readable by the homeserver, and this cannot be turned off again.") wrapMode: Text.WordWrap color: AppPalette.text } onAccepted: root.encryptionRequested(root.chatId) } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group what this room is called on the network", "Address") } ThemedFormCard { Layout.fillWidth: true FormCard.FormTextDelegate { id: aliasDelegate visible: root.canonicalAlias.length > 0 icon.name: "globe" text: i18nc("@label the address a room is published under", "Main address") description: root.canonicalAlias } Repeater { model: root.altAliases delegate: FormCard.FormTextDelegate { required property string modelData icon.name: "globe" text: i18nc("@label another address the same room answers to", "Also reachable as") description: modelData } } FormCard.FormTextDelegate { // the internal id is last and never offered first: it is what the // protocol routes on, not what anybody would type. icon.name: "code-context" text: i18nc("@label the room's internal identifier", "Room identifier") description: root.roomId } } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group edit the room's name and topic", "Room settings") } ThemedFormCard { Layout.fillWidth: true FormCard.FormTextFieldDelegate { label: i18nc("@label:textbox the room's display name", "Name") text: root.roomName onAccepted: matrixRooms.setRoomName(root.chatId, text) } FormCard.FormTextFieldDelegate { label: i18nc("@label:textbox the room's topic", "Topic") text: root.topic onAccepted: matrixRooms.setRoomTopic(root.chatId, text) } } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group messages pinned in this room", "Pinned messages") } ThemedFormCard { Layout.fillWidth: true FormCard.FormTextDelegate { visible: root.pinned.length === 0 text: i18nc("@info no messages are pinned in this room", "Nothing pinned yet") } Repeater { model: root.pinned delegate: FormCard.AbstractFormDelegate { id: pinDelegate required property var modelData Layout.fillWidth: true contentItem: RowLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: pinDelegate.modelData.text || pinDelegate.modelData.eventId textFormat: Text.PlainText elide: Text.ElideRight wrapMode: Text.WordWrap } QQC2.Button { icon.name: "pin-remove" text: i18nc("@action:button unpin a message", "Unpin") onClicked: matrixRooms.unpinMessage(root.chatId, pinDelegate.modelData.eventId) } } } } } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group search the room history", "Search") } ThemedFormCard { Layout.fillWidth: true FormCard.FormTextFieldDelegate { id: searchField label: i18nc("@label:textbox search the room history", "Search") placeholderText: i18nc("@info:placeholder type to search messages", "Type to search messages") onAccepted: matrixRooms.searchMessages(root.chatId, text) } FormCard.FormTextDelegate { visible: root.searchResults.length === 0 && searchField.text.length > 0 text: i18nc("@info no messages matched the search", "No matches") } Repeater { model: root.searchResults delegate: FormCard.AbstractFormDelegate { id: resultDelegate required property var modelData Layout.fillWidth: true contentItem: ColumnLayout { spacing: 0 QQC2.Label { Layout.fillWidth: true text: resultDelegate.modelData.text || resultDelegate.modelData.eventId textFormat: Text.PlainText elide: Text.ElideRight wrapMode: Text.WordWrap } QQC2.Label { Layout.fillWidth: true text: resultDelegate.modelData.sender || "" textFormat: Text.PlainText font: Kirigami.Theme.smallFont color: AppPalette.disabledText } } } } } Kirigami.ListSectionHeader { Layout.fillWidth: true activeFocusOnTab: false text: i18nc("@title:group the people in a Matrix room", "Members") } ThemedFormCard { Layout.fillWidth: true FormCard.FormTextDelegate { visible: root.members.length === 0 icon.name: "user-group-new" text: i18nc("@info the member list has not arrived yet", "No members loaded") description: i18nc("@info:whatsthis", "A homeserver sends the member list lazily, so it may fill in a moment after the room opens.") } FormCard.FormButtonDelegate { visible: root.members.length > root.membersShown.length text: i18nc("@action:button in a room member list, %1 is a number of people", "Show more (of %1)", root.members.length) icon.name: "list-add" onClicked: root.membersShownCount += root.memberPageSize } Repeater { // A room of a few thousand people is possible, and a row per // person carries an avatar whether on screen or not, so the list // is drawn a page at a time. Every member is still reachable. model: root.membersShown delegate: FormCard.AbstractFormDelegate { id: memberDelegate required property var modelData readonly property string powerLabel: RoomRoles.label(memberDelegate.modelData.powerLevel || 0) Layout.fillWidth: true // the card is hung off this row, so this row is what reports // the click - the same contract ContactDelegate has. onClicked: root.memberActivated(memberDelegate.modelData.userId, memberDelegate) contentItem: RowLayout { spacing: Kirigami.Units.largeSpacing Components.Avatar { Layout.alignment: Qt.AlignVCenter implicitWidth: Kirigami.Units.iconSizes.medium implicitHeight: Kirigami.Units.iconSizes.medium name: memberDelegate.modelData.displayName || "" source: memberDelegate.modelData.avatarUrl || "" } ColumnLayout { Layout.fillWidth: true spacing: 0 QQC2.Label { Layout.fillWidth: true text: memberDelegate.modelData.displayName || "" textFormat: Text.PlainText elide: Text.ElideRight } // the identifier under the name, because two people in // one room may call themselves the same thing. QQC2.Label { Layout.fillWidth: true text: memberDelegate.modelData.userId || "" textFormat: Text.PlainText elide: Text.ElideMiddle font: Kirigami.Theme.smallFont color: AppPalette.disabledText } } QQC2.Label { Layout.alignment: Qt.AlignVCenter visible: memberDelegate.powerLabel.length > 0 text: memberDelegate.powerLabel textFormat: Text.PlainText font: Kirigami.Theme.smallFont color: ThemePalette.accent } } } } } Dialogs.FileDialog { id: avatarDialog title: i18nc("@title:window", "Set room avatar") nameFilters: [i18nc("@item file type filter", "Images (*.png *.jpg *.jpeg *.gif *.webp)"), i18nc("@item file type filter", "All files (*)")] // Room avatars get the profile avatar's crop step: the picked file // becomes a square the room frame holds, and only that is uploaded. onAccepted: { roomAvatarCrop.wide = false roomAvatarCrop.sourcePath = String(selectedFile) roomAvatarCrop.open() } } CropSheet { id: roomAvatarCrop onApplied: (outPath) => matrixRooms.setRoomAvatar(root.chatId, outPath) } } } }