// 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 koutnet.app // A plain Page with a RowLayout in it rather than a ScrollablePage, because the // rail runs the full height of the column beside a list that scrolls on its own, // and a ScrollablePage would scroll the rail with it. // // the section headings sit above the view rather than inside it, and the pinned // Favorites row with them. As the ListView's header, folding one changed the // header's height, and QQuickItemView answers a header resize with // updateHeader() and fixupPosition() and nothing else: shrinking clamps contentY // back into bounds, growing does not, so the height the header just got back // appears above the viewport and the section that was unfolded is off the top. Kirigami.Page { id: root // The page is one of the surfaces the theme's tone is painted on, and the // one directly over the wallpaper. A plain Rectangle rather than // Kirigami's gradient, which would be a second wash over the scrim. The // column is raised a step off the conversation beside it so the two are // told apart without a dividing line. // // The panel itself draws no wallpaper image: with transparency it is only a // veil, so the window's wallpaper shows through and can be blurred for this // panel separately in the window backdrop. Zero transparency is the old // opaque column. background: Rectangle { readonly property bool panelTransparent: appSettings.wallpaperPath.length > 0 && appSettings.panelTransparency > 0 color: panelTransparent ? Qt.alpha(ThemePalette.surfaceRaised, Math.max(0.2, 1 - appSettings.panelTransparency / 100)) : ThemePalette.surfaceRaised } // Kept for compatibility with callers that still pass the window backdrop. property Item wallpaperSource: null property Item backdrop: null // The window blurs the wallpaper behind this row for its own setting; the // page only says where the row is rather than drawing a second copy here. readonly property Item profileBarItem: accountRow // Handed to both views below rather than to one, so it cannot be an alias. property var model: null property string selectedChatId: "" property string favoritesChatId: "" property int connectionMode: 0 // Bound from the window: the rail's own switch turns the protocol filter // off so every protocol's chats show at once. property bool showChatsFromAllProtocols: false // NeoChat's Direct Messages space: one-to-one chats only. property bool directOnly: false property bool micMuted: false property bool deafened: false // in compact mode the rail goes - its modes are all on the settings page and // the buttons are wider than the list - and so do the headings. property bool compact: false // The column dragged down to a strip of avatars, distinct from compact, // which is a user-chosen mode that also hands the window to the list. // Measured against a width Main.qml works out of the row's own padding and // avatar, because that is where a row runs out of room for anything else. // Zero means never, for a page used on its own. property real narrowBelowWidth: 0 readonly property bool avatarOnly: root.narrowBelowWidth > 0 && root.width > 0 && root.width < root.narrowBelowWidth // Either way the headings and the rail go: at this width there is no room // for a label, and a heading that cannot be folded is a way back lost. readonly property bool bare: root.avatarOnly || root.compact // The conversation whose face was tapped once in a strip of avatars, or // empty. In a narrow column a tap can mean open the conversation or open // its menu, and a right-click is not on every pointing device, so the // second tap on the same face opens the menu. Dropped when the column // widens, where a name makes the arrangement unnecessary. property string avatarAwaitingSecondTap: "" // Answers a tap on a face, arms the next one and says whether this tap was // the second. One function because the two are one piece of state: a caller // that did one without the other leaves a face that opens its menu without // opening its chat. function avatarTapWantsMenu(chatId) { if (chatId.length === 0) return false if (root.avatarAwaitingSecondTap === chatId) { root.avatarAwaitingSecondTap = "" return true } root.avatarAwaitingSecondTap = chatId return false } onAvatarOnlyChanged: { // Nothing is waiting for a second tap in a column that is wide enough to // say what every row is. if (!root.avatarOnly) root.avatarAwaitingSecondTap = "" } property bool favoritesExpanded: true property bool invitesExpanded: true // Which folders are unfolded, keyed by folder id: a new folder starts open, // an untouched one keeps what it had rather than snapping shut. property var folderOpen: ({}) // Held open wherever the headings are not drawn: a fold with no chevron left // to undo it is a row that has gone for good. readonly property bool favoritesShown: root.bare || root.favoritesExpanded function isFolderOpen(folderId) { if (root.bare) return true const stored = root.folderOpen[folderId] return stored === undefined ? true : stored === true } function setFolderOpen(folderId, open) { const next = Object.assign({}, root.folderOpen) next[folderId] = open root.folderOpen = next } // The folders the list is split into: group chats and one-to-one chats // always, anything the user made below them - by what the conversation is, // not by transport, which the rail above already says. readonly property var folders: ChatFolders.folders // Whether there is anything to draw, which the placeholder asks. Not // model.rowCount(): that is a plain C++ call evaluated once, so the // placeholder stayed over a full list. The folder counts are properties, // so the binding re-evaluates as chats arrive and go - and every chat is in // one folder or the other. readonly property int shownChatCount: { let total = 0 for (let i = 0; i < root.folders.length; ++i) total += root.folders[i].count return total } function folderCount(folderId) { for (let i = 0; i < root.folders.length; ++i) { if (root.folders[i].id === folderId) return root.folders[i].count } return 0 } // One row per Matrix invitation, kept out of the conversation model: an // invitation is not a conversation and carries buttons, not a preview. property var invites: null signal chatActivated(string chatId) signal newChatRequested() // rail Create, makes a Matrix room instead of opening the transport picker. signal createRoomRequested() signal forgetRequested(string chatId) signal clearRequested(string chatId) // Remove the row and the saved history, this device only. A joined room // comes back on the next login, which is what separates this from Leave. signal deleteRequested(string chatId) signal inviteAccepted(string chatId) signal inviteDeclined(string chatId) // the pinned saved-messages row, which is the only one that can be // emptied: forgetting it is not on offer, so clearing it is. property string selfChatId: "" signal leaveRoomRequested(string chatId) signal profileRequested(Item anchorItem) signal settingsRequested() signal connectionModeRequested(int mode) signal homeRequested() signal personalMessagesRequested() signal browseRequested() signal micToggled() signal deafenToggled() // the row that was clicked travels with the request: the card is anchored to // it, and only this page knows which delegate it was. signal peerCardRequested(string chatId, Item anchorItem) readonly property string favoritesName: i18nc("@item conversation list, chat with yourself", "Favorites") // the needle lives here, not on the field. titleDelegate is a Component, so // an id inside it is in a scope of its own and does not resolve from here - // matchesSearch() threw ReferenceError, the binding stayed at its last // value, and folding a section became final. property string searchText: "" // Folding hides rows, so typing has to unfold them again or the search appears // to find nothing. onSearchTextChanged: if (root.searchText.length > 0) { root.favoritesExpanded = true root.folderOpen = {} } title: i18nc("@title sidebar section, the list of conversations", "Chats") padding: 0 // See the note on Kirigami.Theme in Main.qml. // Search and "new chat" go in the toolbar, not a strip under it: in a // seventeen unit column a row each costs two rows of conversations. // Squeezed to avatars, only the new-chat button stays - a column of // conversations with no way to start one is a dead end. titleDelegate: RowLayout { Layout.fillWidth: true spacing: Kirigami.Units.smallSpacing Kirigami.SearchField { Layout.fillWidth: true visible: !root.avatarOnly placeholderText: root.compact ? "" : i18nc("@info:placeholder filter the conversation list", "Search") // Round-trip both ways: the write keeps the page in step with the // text, the binding puts it back if the header is reloaded. text: root.searchText onTextChanged: root.searchText = text } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "mail-message-new" text: i18nc("@action:button start a conversation with a peer that is not in the list yet", "New chat") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: root.newChatRequested() } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly visible: !root.avatarOnly icon.name: "folder-new" text: i18nc("@action:button group conversations into a new folder", "New folder") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: { folderDialog.folderId = "" nameField.text = "" folderDialog.open() } } } // Matches the address as well as the name, since an unnamed peer only has the // former; here so the pinned row and the conversations use the same rule. function matchesSearch(displayName, chatId) { if (root.searchText.length === 0) return true const needle = root.searchText.toLowerCase() return displayName.toLowerCase().indexOf(needle) !== -1 || chatId.toLowerCase().indexOf(needle) !== -1 } RowLayout { anchors.fill: parent spacing: 0 ConnectionRail { Layout.fillHeight: true visible: !root.bare currentMode: root.connectionMode chats: root.model showingHome: !root.directOnly showingPersonalMessages: root.directOnly onModeSelected: (mode) => root.connectionModeRequested(mode) onHomeRequested: root.homeRequested() onPersonalMessagesRequested: root.personalMessagesRequested() onCreateRequested: root.createRoomRequested() onBrowseRequested: root.browseRequested() } Kirigami.Separator { Layout.fillHeight: true visible: !root.bare Layout.preferredWidth: 1 } ColumnLayout { Layout.fillWidth: true Layout.fillHeight: true spacing: 0 ChatSection { Layout.fillWidth: true visible: !root.bare && !root.directOnly text: root.favoritesName itemCount: 1 expanded: root.favoritesExpanded onToggleRequested: root.favoritesExpanded = !root.favoritesExpanded } // Wrapped in an Item because RoundedItemDelegate binds its own width // to the view it delegates, and this one delegates nothing. // // The fold is tested on the wrapper: binding to favoritesRow.visible // read effective visibility, so once down it never came back. Item { Layout.fillWidth: true implicitHeight: favoritesRow.implicitHeight visible: !root.directOnly && root.favoritesShown && root.matchesSearch(root.favoritesName, root.favoritesChatId) ContactDelegate { id: favoritesRow width: parent.width displayName: root.favoritesName iconName: AppPalette.dark ? "bookmarks-symbolic" : "bookmarks" compact: root.compact avatarOnly: root.avatarOnly showPresence: false selected: root.selectedChatId === root.favoritesChatId onClicked: root.chatActivated(root.favoritesChatId) // Not the contact card, because a pseudo-chat has no peer // behind it, and not two taps either: in a strip of avatars // this face does the one thing the row does. onAvatarClicked: root.chatActivated(root.favoritesChatId) // The saved-messages row answers a right-click with the one // menu, in its own shape: no peer to forget and no folder to // leave, so open, clear, and nothing else (see rowMenu.isSelf). function openRowMenu() { rowMenu.chatId = root.favoritesChatId rowMenu.chatName = root.favoritesName rowMenu.isRoom = false rowMenu.isInvite = false rowMenu.isSelf = true rowMenu.popup() } onPressAndHold: favoritesRow.openRowMenu() TapHandler { acceptedButtons: Qt.RightButton onTapped: favoritesRow.openRowMenu() } } } // the placeholder is a sibling of the scroll area: as a child of a // Flickable it would be parented to the content and scroll away. Item { Layout.fillWidth: true Layout.fillHeight: true Kirigami.PlaceholderMessage { anchors.centerIn: parent width: parent.width - Kirigami.Units.largeSpacing * 4 visible: root.directOnly ? root.folderCount("direct") === 0 : root.shownChatCount === 0 && (root.invites === null || root.invites.count === 0) icon.name: "dialog-messages" text: root.directOnly ? i18nc("@info there are no one-to-one conversations yet", "No personal messages yet") : i18nc("@info there are no conversations yet", "No chats yet") explanation: root.directOnly ? i18nc("@info", "Start one from the New chat button, or wait for someone to write to you.") : i18nc("@info", "Start one from the button in the toolbar, or wait for someone to write to you.") } // two sections over the same model, each collapsing the rows // that are not its own. One view cannot do it: the model is // ordered by activity, so rooms and direct chats interleave and // a heading drawn from that order would repeat. // // Repeaters rather than ListViews: a ListView sized to its // content starts at zero, creates no delegates and stays there. // Tens of rows make building all of them cheaper. QQC2.ScrollView { id: chatsScroll anchors.fill: parent contentWidth: availableWidth ColumnLayout { width: chatsScroll.availableWidth spacing: 0 ChatSection { Layout.fillWidth: true text: i18nc("@title:group conversation list section, Matrix room invitations", "Invitations") itemCount: root.invites ? root.invites.count : 0 visible: !root.bare && !root.directOnly && root.invites !== null && root.invites.count > 0 expanded: root.invitesExpanded onToggleRequested: root.invitesExpanded = !root.invitesExpanded } ColumnLayout { Layout.fillWidth: true spacing: 0 // Held open wherever the heading is not drawn: with // no chevron, an unseen invitation cannot be answered. visible: !root.directOnly && (root.bare || root.invitesExpanded) Repeater { // for the same reason the folders are: folded // away means not built, not built and hidden. model: !root.directOnly && (root.bare || root.invitesExpanded) ? root.invites : null delegate: inviteRowComponent } } // One section per folder, drawing only its own rows: the // model is ordered by activity, so the kinds interleave // and one heading would repeat. Repeater { model: root.folders delegate: ChatFolderSection { required property var modelData folder: modelData bare: root.bare chatModel: root.model rowComponent: chatRowComponent // directOnly keeps the direct folder, and keeps it open. visible: (!root.directOnly || modelData.id === "direct") && (modelData.count > 0 || modelData.editable) sectionShown: root.directOnly || root.isFolderOpen(modelData.id) onToggleRequested: (folderId) => root.setFolderOpen(folderId, !root.isFolderOpen(folderId)) onMenuRequested: (folderId, folderName) => { folderMenu.folderId = folderId folderMenu.folderName = folderName folderMenu.popup() } } } } } } } } // one menu for both groups, so a long list does not build a hundred of them. Components.ConvergentContextMenu { id: rowMenu property string chatId: "" property string chatName: "" property bool isRoom: false // An invitation rather than a conversation: a wide column puts accept // and decline beside the row, a strip of avatars has room for neither. property bool isInvite: false // The saved-messages row: a pseudo-chat has no peer, so move, forget // and delete are folded away, leaving open and clear. property bool isSelf: false Kirigami.Action { text: i18nc("@action:inmenu open this conversation", "Open") icon.name: "document-open" onTriggered: root.chatActivated(rowMenu.chatId) } Kirigami.Action { text: i18nc("@action:inmenu accept a room invitation", "Accept") icon.name: "dialog-ok" visible: rowMenu.isInvite onTriggered: root.inviteAccepted(rowMenu.chatId) } Kirigami.Action { text: i18nc("@action:inmenu decline a room invitation", "Decline") icon.name: "dialog-cancel" visible: rowMenu.isInvite onTriggered: root.inviteDeclined(rowMenu.chatId) } Kirigami.Action { text: i18nc("@action:inmenu remove the conversation from the list, keeping the history", "Forget this chat") icon.name: "list-remove" // A room is left rather than forgotten: dropping the row would bring // it back on the next sync. An invitation is neither - it is not a // conversation yet and there is nothing to forget. visible: !rowMenu.isRoom && !rowMenu.isInvite && !rowMenu.isSelf onTriggered: root.forgetRequested(rowMenu.chatId) } Kirigami.Action { text: i18nc("@action:inmenu empty the saved messages chat", "Clear this chat") icon.name: "edit-clear-all" visible: rowMenu.chatId.length > 0 && rowMenu.chatId === root.selfChatId onTriggered: root.clearRequested(rowMenu.chatId) } Kirigami.Action { text: i18nc("@action:inmenu leave a Matrix room", "Leave room") icon.name: "window-close" visible: rowMenu.isRoom onTriggered: root.leaveRoomRequested(rowMenu.chatId) } Kirigami.Action { text: i18nc("@action:inmenu delete the conversation and its history on this device only", "Delete this chat here") icon.name: "edit-delete" visible: !rowMenu.isInvite && !rowMenu.isSelf onTriggered: root.deleteRequested(rowMenu.chatId) } Kirigami.Action { separator: true visible: rowMenu.chatId.length > 0 } // Which folder a conversation sits in: one folder only, or the same // conversation would be two rows saying one thing. An invitation is // not in the list yet and has no folder to move to. Kirigami.Action { text: i18nc("@action:inmenu put this conversation in another folder", "Move to folder") icon.name: "folder" visible: rowMenu.chatId.length > 0 && !rowMenu.isInvite && !rowMenu.isSelf onTriggered: moveMenu.popup() } } QQC2.Menu { id: moveMenu // A Repeater cannot build a menu: a menu is a column of Items and an // Action is not one, so the folders are added as objects that complete // themselves. Instantiator { id: moveMenuActions model: root.folders delegate: Kirigami.Action { required property var modelData text: modelData.name icon.name: modelData.id === "rooms" ? "group-chat" : (modelData.editable ? "folder" : "dialog-messages") checked: ChatFolders.folderFor(rowMenu.chatId) === modelData.id onTriggered: ChatFolders.assign(rowMenu.chatId, modelData.id) } onObjectAdded: (index, object) => moveMenu.insertAction(index, object) onObjectRemoved: (index, object) => moveMenu.removeAction(object) } } // One dialog for "New folder" and "Rename": they ask the same question, and // two dialogs would be two places for the answer to go. Kirigami.Dialog { id: folderDialog property string folderId: "" title: folderDialog.folderId.length > 0 ? i18nc("@title:window", "Rename folder") : i18nc("@title:window", "New folder") modal: true // QQC2, not a bare Overlay: this file imports Controls under that alias // only, and a dialog whose anchors name an undefined object never opens. anchors.centerIn: QQC2.Overlay.overlay standardButtons: QQC2.Dialog.Ok | QQC2.Dialog.Cancel onAccepted: { if (folderDialog.folderId.length > 0) ChatFolders.renameFolder(folderDialog.folderId, nameField.text) else ChatFolders.addFolder(nameField.text) } contentItem: QQC2.TextField { id: nameField placeholderText: i18nc("@info:placeholder", "Folder name") } } Components.ConvergentContextMenu { id: folderMenu property string folderId: "" property string folderName: "" Kirigami.Action { text: i18nc("@action:inmenu rename this folder", "Rename...") icon.name: "edit-rename" onTriggered: { folderDialog.folderId = folderMenu.folderId nameField.text = folderMenu.folderName folderDialog.open() } } Kirigami.Action { text: i18nc("@action:inmenu delete this folder; the chats in it go back to the built-in folders", "Delete folder") icon.name: "edit-delete" onTriggered: ChatFolders.removeFolder(folderMenu.folderId) } } // an invitation is not a conversation: no preview, no unread count, just a // name and two buttons. The name can lag behind the room, so the row falls // back to the room address. Component { id: inviteRowComponent Item { id: inviteWrapper Layout.fillWidth: true implicitHeight: inviteColumn.implicitHeight ColumnLayout { id: inviteColumn width: parent.width spacing: 0 ContactDelegate { Layout.fillWidth: true compact: root.compact avatarOnly: root.avatarOnly displayName: model.displayName.length > 0 ? model.displayName : model.chatId preview: model.displayName.length > 0 ? model.chatId : "" showPresence: false function openRowMenu() { rowMenu.chatId = model.chatId rowMenu.chatName = model.displayName rowMenu.isInvite = true // One menu serves conversation, invitation and // saved-messages rows, so the flags that tell them apart // are set here, not left from the last row that opened it. rowMenu.isRoom = false rowMenu.isSelf = false root.avatarAwaitingSecondTap = "" rowMenu.popup() } // One tap, not the two the conversation rows have: there is // nothing to open, since the account has not joined the room, // and the only thing to do is accept or decline. // // A wide column has the two buttons under the row; a strip of // avatars has no room for them, so the face is the way in. onAvatarClicked: openRowMenu() } RowLayout { Layout.fillWidth: true Layout.leftMargin: Kirigami.Units.largeSpacing Layout.rightMargin: Kirigami.Units.largeSpacing Layout.bottomMargin: Kirigami.Units.smallSpacing visible: !root.bare spacing: Kirigami.Units.smallSpacing QQC2.Button { Layout.fillWidth: true text: i18nc("@action:button accept a room invitation", "Accept") icon.name: "dialog-ok" highlighted: true onClicked: root.inviteAccepted(model.chatId) } QQC2.Button { Layout.fillWidth: true text: i18nc("@action:button decline a room invitation", "Decline") icon.name: "dialog-cancel" onClicked: root.inviteDeclined(model.chatId) } } } } } // one delegate for every folder. The folder it was built into decides which // rows it draws; the rest is the same, because a group chat and a // one-to-one are both a conversation with something new in it. // // Wrapped in an Item for the reason the pinned row is: a RoundedItemDelegate // binds its own width to the view it delegates, and this one delegates none. Component { id: chatRowComponent Item { id: rowWrapper // model.* rather than required properties: each role shares its name // with a ContactDelegate property and would bind to itself. readonly property bool isRoom: model.isRoom // the folder this was built into - see the note beside folderGroup. readonly property bool inThisSection: rowWrapper.parent !== null && ChatFolders.folderFor(model.chatId) === rowWrapper.parent.folderId readonly property bool matchesProtocol: root.showChatsFromAllProtocols || model.transportGroup === root.connectionMode readonly property bool shown: rowWrapper.inThisSection && rowWrapper.parent.sectionShown && rowWrapper.matchesProtocol && root.matchesSearch(model.displayName, model.chatId) Layout.fillWidth: true implicitHeight: rowWrapper.shown ? chatRow.implicitHeight : 0 visible: rowWrapper.shown ContactDelegate { id: chatRow width: parent.width compact: root.compact avatarOnly: root.avatarOnly displayName: model.displayName preview: model.preview stampSecs: model.stampSecs lastSeenSecs: model.lastSeenSecs unreadCount: model.unreadCount online: model.online transport: model.transport avatarSource: model.avatarSource // A Matrix room has no presence, and a permanently grey dot // reads as a peer switched off rather than one not asked. showPresence: !rowWrapper.isRoom selected: model.chatId === root.selectedChatId function openRowMenu() { rowMenu.chatId = model.chatId rowMenu.chatName = model.displayName rowMenu.isRoom = rowWrapper.isRoom // One menu serves conversation and invitation rows, so the // flag that tells them apart is set here. rowMenu.isInvite = false rowMenu.isSelf = false // The menu is open, so no second tap is pending - including // after a right-click, which reaches the same menu and would // otherwise leave the face armed. root.avatarAwaitingSecondTap = "" rowMenu.popup() } onClicked: root.chatActivated(model.chatId) onPressAndHold: chatRow.openRowMenu() // What a tap on the face means, the only place width matters. // Wide, the face asks about the person: the contact card. // Narrow, the face is the whole row, so the first tap opens the // conversation and a second opens its menu. onAvatarClicked: (anchorItem) => { if (root.avatarOnly) { if (root.avatarTapWantsMenu(model.chatId)) chatRow.openRowMenu() else root.chatActivated(model.chatId) return } root.peerCardRequested(model.chatId, anchorItem) } TapHandler { acceptedButtons: Qt.RightButton onTapped: chatRow.openRowMenu() } } } } // Gone in compact mode rather than shrunk: the microphone, deafen and // settings are in the drawer and on the tray icon already. footer: AccountRow { id: accountRow visible: !root.bare compact: root.compact micMuted: root.micMuted deafened: root.deafened onProfileRequested: (anchorItem) => root.profileRequested(anchorItem) onSettingsRequested: root.settingsRequested() onMicToggled: root.micToggled() onDeafenToggled: root.deafenToggled() } }