Warning, /network/neochat/src/qml/UserSearchPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import Qt.labs.qmlmodels
0008 
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.delegates as Delegates
0011 import org.kde.kirigamiaddons.labs.components as Components
0012 
0013 import org.kde.neochat
0014 
0015 /**
0016  * @brief Component for finding users from the public list.
0017  *
0018  * This component is based on a SearchPage and allows the user to enter a search
0019  * term into the input field and then search the room for messages with text that
0020  * matches the input.
0021  *
0022  * @sa SearchPage
0023  */
0024 SearchPage {
0025     id: root
0026 
0027     /**
0028      * @brief The connection for the current local user.
0029      */
0030     required property NeoChatConnection connection
0031 
0032     title: i18nc("@action:title", "Find Your Friends")
0033 
0034     Component.onCompleted: focusSearch()
0035 
0036     model: UserDirectoryListModel {
0037         id: userSearchModel
0038         connection: root.connection
0039     }
0040 
0041     listHeaderDelegate: Delegates.RoundedItemDelegate {
0042         onClicked: _private.openManualUserDialog()
0043 
0044         text: i18n("Enter a user ID")
0045         icon.name: "list-add-user"
0046         icon.width: Kirigami.Units.gridUnit * 2
0047         icon.height: Kirigami.Units.gridUnit * 2
0048     }
0049 
0050     modelDelegate: Delegates.RoundedItemDelegate {
0051         id: userDelegate
0052         required property string userId
0053         required property string displayName
0054         required property url avatarUrl
0055         required property var directChatExists
0056 
0057         text: displayName
0058 
0059         onClicked: {
0060             root.connection.openOrCreateDirectChat(userDelegate.userId);
0061             root.closeDialog();
0062         }
0063 
0064         contentItem: RowLayout {
0065             spacing: Kirigami.Units.smallSpacing
0066 
0067             Components.Avatar {
0068                 Layout.preferredWidth: Kirigami.Units.gridUnit * 2
0069                 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0070                 Layout.alignment: Qt.AlignTop
0071 
0072                 source: userDelegate.avatarUrl
0073                 name: userDelegate.displayName
0074             }
0075             Delegates.SubtitleContentItem {
0076                 itemDelegate: userDelegate
0077                 subtitle: userDelegate.userId
0078                 labelItem.textFormat: Text.PlainText
0079             }
0080             QQC2.Label {
0081                 visible: userDelegate.directChatExists
0082                 text: i18n("Friends")
0083                 textFormat: Text.PlainText
0084                 color: Kirigami.Theme.positiveTextColor
0085             }
0086         }
0087     }
0088 
0089     searchFieldPlaceholder: i18n("Find your friends…")
0090     noSearchPlaceholderMessage: i18n("Enter text to start searching for your friends")
0091     noResultPlaceholderMessage: i18nc("@info:label", "No matches found")
0092 
0093     Component {
0094         id: manualUserDialog
0095         ManualUserDialog {}
0096     }
0097 
0098     QtObject {
0099         id: _private
0100         function openManualUserDialog() {
0101             let dialog = manualUserDialog.createObject(applicationWindow().overlay, {
0102                 connection: root.connection
0103             });
0104             dialog.accepted.connect(() => {
0105                 root.closeDialog();
0106             });
0107             dialog.open();
0108         }
0109     }
0110 }