// 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 koutnet.app // NeoChat's Explore page: the homeserver's public rooms, a search field, and a // manual join for addresses the directory misses. Kirigami.Page { id: root // same surface as the other pages. background: Rectangle { color: ThemePalette.surface } title: i18nc("@title:window the public rooms of the Matrix homeserver", "Browse rooms") padding: 0 property string searchText: "" signal roomJoinRequested(string roomOrAlias) signal roomOpenRequested(string chatId) Component.onCompleted: matrixDirectory.search("") Connections { target: matrixDirectory // a signed-out fetch leaves an empty list, refetch when a session lands. function onAvailableChanged() { if (matrixDirectory.available) matrixDirectory.search(root.searchText) } } Timer { id: searchTimer interval: 350 onTriggered: matrixDirectory.search(root.searchText) } ColumnLayout { anchors.fill: parent spacing: 0 // join by address, NeoChat's "Enter a Room Manually". RowLayout { Layout.fillWidth: true Layout.margins: Kirigami.Units.largeSpacing spacing: Kirigami.Units.smallSpacing QQC2.TextField { id: addressField Layout.fillWidth: true enabled: matrixDirectory.available placeholderText: i18nc("@info:placeholder a room alias or id to join directly", "Room address or alias, e.g. #room:server") onAccepted: if (text.trim().length > 0) root.roomJoinRequested(text.trim()) } QQC2.Button { text: i18nc("@action:button join the room whose address was typed", "Join") icon.name: "list-add" enabled: matrixDirectory.available && addressField.text.trim().length > 0 onClicked: root.roomJoinRequested(addressField.text.trim()) } } Kirigami.Separator { Layout.fillWidth: true } RowLayout { Layout.fillWidth: true Layout.leftMargin: Kirigami.Units.largeSpacing Layout.rightMargin: Kirigami.Units.largeSpacing Layout.topMargin: Kirigami.Units.largeSpacing spacing: Kirigami.Units.smallSpacing Kirigami.SearchField { Layout.fillWidth: true enabled: matrixDirectory.available placeholderText: i18nc("@info:placeholder search the public room directory", "Find a public room") text: root.searchText onTextChanged: { root.searchText = text searchTimer.restart() } onAccepted: { searchTimer.stop() matrixDirectory.search(root.searchText) } } QQC2.BusyIndicator { visible: matrixDirectory.loading running: visible implicitWidth: Kirigami.Units.iconSizes.smallMedium implicitHeight: Kirigami.Units.iconSizes.smallMedium } } Kirigami.InlineMessage { Layout.fillWidth: true Layout.leftMargin: Kirigami.Units.largeSpacing Layout.rightMargin: Kirigami.Units.largeSpacing Layout.topMargin: Kirigami.Units.smallSpacing visible: matrixDirectory.error.length > 0 type: Kirigami.MessageType.Error text: matrixDirectory.error } QQC2.ScrollView { Layout.fillWidth: true Layout.fillHeight: true contentWidth: availableWidth visible: matrixDirectory.rooms.length > 0 ListView { model: matrixDirectory.rooms spacing: Kirigami.Units.smallSpacing topMargin: Kirigami.Units.largeSpacing bottomMargin: Kirigami.Units.largeSpacing leftMargin: Kirigami.Units.largeSpacing rightMargin: Kirigami.Units.largeSpacing delegate: Kirigami.AbstractCard { width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin contentItem: RowLayout { spacing: Kirigami.Units.largeSpacing AnimatedAvatar { Layout.alignment: Qt.AlignTop implicitWidth: Kirigami.Units.iconSizes.large implicitHeight: Kirigami.Units.iconSizes.large name: modelData.name.length > 0 ? modelData.name : modelData.roomId source: modelData.avatarUrl } ColumnLayout { Layout.fillWidth: true spacing: 0 Kirigami.Heading { Layout.fillWidth: true level: 4 text: modelData.name.length > 0 ? modelData.name : modelData.roomId textFormat: Text.PlainText elide: Text.ElideRight } QQC2.Label { Layout.fillWidth: true visible: modelData.topic.length > 0 text: modelData.topic textFormat: Text.PlainText elide: Text.ElideRight color: AppPalette.disabledText } QQC2.Label { Layout.fillWidth: true text: i18nc("@info %1 is the number of people in a public room", "%1 members", modelData.members) font: Kirigami.Theme.smallFont color: AppPalette.disabledText } } QQC2.Button { text: modelData.joined ? i18nc("@action:button open a room already joined", "Open") : i18nc("@action:button join this public room", "Join") highlighted: !modelData.joined onClicked: modelData.joined ? root.roomOpenRequested(matrixDirectory.chatIdForRoom(modelData.roomId)) : root.roomJoinRequested(modelData.roomId) } } } } } Kirigami.PlaceholderMessage { Layout.fillWidth: true Layout.fillHeight: true visible: matrixDirectory.available && !matrixDirectory.loading && matrixDirectory.rooms.length === 0 && matrixDirectory.error.length === 0 icon.name: "compass" text: root.searchText.length > 0 ? i18nc("@info:label the search found no public rooms", "No rooms found") : i18nc("@info:label the homeserver lists no public rooms", "No public rooms") explanation: root.searchText.length > 0 ? i18nc("@info", "Try another name, or join the room by its address above.") : i18nc("@info", "This homeserver has not published any rooms in its directory.") } } }