Space Search

Allow to refine searches to spaces only in the main exlore function.
Show which rooms are spaces in the search page.

Closes #577
This commit is contained in:
James Graham
2024-03-30 19:37:46 +00:00
parent 482d61ee47
commit 64b8cd5bcc
6 changed files with 64 additions and 7 deletions

View File

@@ -124,6 +124,15 @@ void PublicRoomListModel::setShowOnlySpaces(bool showOnlySpaces)
} }
m_showOnlySpaces = showOnlySpaces; m_showOnlySpaces = showOnlySpaces;
Q_EMIT showOnlySpacesChanged(); Q_EMIT showOnlySpacesChanged();
nextBatch = QString();
attempted = false;
if (job) {
job->abandon();
job = nullptr;
Q_EMIT searchingChanged();
}
} }
void PublicRoomListModel::search(int limit) void PublicRoomListModel::search(int limit)
@@ -243,6 +252,9 @@ QVariant PublicRoomListModel::data(const QModelIndex &index, int role) const
return m_connection->room(room.roomId, JoinState::Join) != nullptr; return m_connection->room(room.roomId, JoinState::Join) != nullptr;
} }
if (role == IsSpaceRole) {
return room.roomType == QLatin1String("m.space");
}
return {}; return {};
} }
@@ -259,6 +271,7 @@ QHash<int, QByteArray> PublicRoomListModel::roleNames() const
roles[AllowGuestsRole] = "allowGuests"; roles[AllowGuestsRole] = "allowGuests";
roles[WorldReadableRole] = "worldReadable"; roles[WorldReadableRole] = "worldReadable";
roles[IsJoinedRole] = "isJoined"; roles[IsJoinedRole] = "isJoined";
roles[IsSpaceRole] = "isSpace";
roles[AliasRole] = "alias"; roles[AliasRole] = "alias";
return roles; return roles;

View File

@@ -69,6 +69,7 @@ public:
AllowGuestsRole, /**< Whether the room allows guest users. */ AllowGuestsRole, /**< Whether the room allows guest users. */
WorldReadableRole, /**< Whether the room events can be seen by non-members. */ WorldReadableRole, /**< Whether the room events can be seen by non-members. */
IsJoinedRole, /**< Whether the local user has joined the room. */ IsJoinedRole, /**< Whether the local user has joined the room. */
IsSpaceRole, /**< Whether the room is a space. */
}; };
explicit PublicRoomListModel(QObject *parent = nullptr); explicit PublicRoomListModel(QObject *parent = nullptr);

View File

@@ -32,7 +32,13 @@ SearchPage {
/** /**
* @brief Whether results should only includes spaces. * @brief Whether results should only includes spaces.
*/ */
property bool showOnlySpaces: false property bool showOnlySpaces: spacesOnlyButton.checked
onShowOnlySpacesChanged: updateSearch()
/**
* @brief Whetherthe button to toggle the showOnlySpaces state should be shown.
*/
property bool showOnlySpacesButton: true
/** /**
* @brief Signal emitted when a room is selected. * @brief Signal emitted when a room is selected.
@@ -47,9 +53,22 @@ SearchPage {
Component.onCompleted: focusSearch() Component.onCompleted: focusSearch()
headerTrailing: ServerComboBox { headerTrailing: RowLayout {
id: serverComboBox QQC2.Button {
connection: root.connection id: spacesOnlyButton
icon.name: "globe"
display: QQC2.Button.IconOnly
checkable: true
text: i18nc("@action:button", "Only show spaces")
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
ServerComboBox {
id: serverComboBox
connection: root.connection
}
} }
model: PublicRoomListModel { model: PublicRoomListModel {

View File

@@ -21,6 +21,7 @@ Delegates.RoundedItemDelegate {
required property string topic required property string topic
required property int memberCount required property int memberCount
required property bool isJoined required property bool isJoined
required property bool isSpace
property bool justJoined: false property bool justJoined: false
/** /**
@@ -56,7 +57,7 @@ Delegates.RoundedItemDelegate {
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Kirigami.Heading { Kirigami.Heading {
Layout.fillWidth: true Layout.fillWidth: !spaceLabel.visible
level: 4 level: 4
text: root.displayName text: root.displayName
font.bold: true font.bold: true
@@ -64,6 +65,13 @@ Delegates.RoundedItemDelegate {
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
QQC2.Label {
id: spaceLabel
Layout.fillWidth: true
visible: root.isSpace
text: i18nc("@info:label A matrix space", "Space")
color: Kirigami.Theme.linkColor
}
QQC2.Label { QQC2.Label {
visible: root.isJoined || root.justJoined visible: root.isJoined || root.justJoined
text: i18n("Joined") text: i18n("Joined")

View File

@@ -82,6 +82,13 @@ Kirigami.ScrollablePage {
searchField.forceActiveFocus(); searchField.forceActiveFocus();
} }
/**
* @brief Force the search to be updated if the model has a valid search function.
*/
function updateSearch() {
searchTimer.restart();
}
header: QQC2.Control { header: QQC2.Control {
padding: Kirigami.Units.largeSpacing padding: Kirigami.Units.largeSpacing
@@ -119,11 +126,18 @@ Kirigami.ScrollablePage {
QQC2.Button { QQC2.Button {
id: searchButton id: searchButton
icon.name: "search" icon.name: "search"
display: QQC2.Button.IconOnly
text: i18nc("@action:button", "Search")
onClicked: { onClicked: {
if (typeof model.search === 'function') { if (typeof model.search === 'function') {
model.search(); model.search();
} }
} }
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
} }
Timer { Timer {
id: searchTimer id: searchTimer

View File

@@ -51,7 +51,8 @@ Kirigami.Dialog {
onClicked: { onClicked: {
let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), { let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), {
connection: root.room.connection, connection: root.room.connection,
showOnlySpaces: true showOnlySpaces: true,
showOnlySpacesButton: false
}, { }, {
title: i18nc("@title", "Choose Parent Space") title: i18nc("@title", "Choose Parent Space")
}); });
@@ -135,7 +136,8 @@ Kirigami.Dialog {
onClicked: { onClicked: {
let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), { let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), {
connection: root.room.connection, connection: root.room.connection,
showOnlySpaces: true showOnlySpaces: true,
showOnlySpacesButton: false
}, { }, {
title: i18nc("@title", "Explore Rooms") title: i18nc("@title", "Explore Rooms")
}); });