Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F115163
D10.1732649452.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D10.1732649452.diff
View Options
diff --git a/src/contents/ui/MainPage.qml b/src/contents/ui/MainPage.qml
--- a/src/contents/ui/MainPage.qml
+++ b/src/contents/ui/MainPage.qml
@@ -20,25 +20,34 @@
onCurrentTagIdChanged: sdkVars.roomList.setTagId(currentTagId)
- header: RowLayout {
- ToolButton {
- icon.name: 'clock'
+ header: ColumnLayout {
+ TextField {
+ text: sdkVars.roomList.filter
+ onTextChanged: sdkVars.roomList.filter = text
+ placeholderText: l10n.get('main-page-room-filter-prompt')
Layout.fillWidth: true
- text: l10n.get('main-page-recent-tab-title')
- onClicked: currentTagId = ''
- display: AbstractButton.TextUnderIcon
- checkable: true
- checked: currentTagId === ''
}
- ToolButton {
- icon.name: 'non-starred-symbolic'
- Layout.fillWidth: true
- text: l10n.get('main-page-favourites-tab-title')
- onClicked: currentTagId = 'm.favourite'
- display: AbstractButton.TextUnderIcon
- checkable: true
- checked: currentTagId === 'm.favourite'
+ RowLayout {
+ ToolButton {
+ icon.name: 'clock'
+ Layout.fillWidth: true
+ text: l10n.get('main-page-recent-tab-title')
+ onClicked: currentTagId = ''
+ display: AbstractButton.TextUnderIcon
+ checkable: true
+ checked: currentTagId === ''
+ }
+
+ ToolButton {
+ icon.name: 'non-starred-symbolic'
+ Layout.fillWidth: true
+ text: l10n.get('main-page-favourites-tab-title')
+ onClicked: currentTagId = 'm.favourite'
+ display: AbstractButton.TextUnderIcon
+ checkable: true
+ checked: currentTagId === 'm.favourite'
+ }
}
}
diff --git a/src/l10n/cmn-Hans/100-ui.ftl b/src/l10n/cmn-Hans/100-ui.ftl
--- a/src/l10n/cmn-Hans/100-ui.ftl
+++ b/src/l10n/cmn-Hans/100-ui.ftl
@@ -45,6 +45,7 @@
main-page-favourites-tab-title = 最爱
main-page-people-tab-title = 人们
main-page-rooms-tab-title = 房间
+main-page-room-filter-prompt = 过滤房间...
room-list-view-room-item-title-name = { $name }
room-list-view-room-item-title-heroes = { $hero } { $otherNum ->
diff --git a/src/l10n/en/100-ui.ftl b/src/l10n/en/100-ui.ftl
--- a/src/l10n/en/100-ui.ftl
+++ b/src/l10n/en/100-ui.ftl
@@ -45,6 +45,7 @@
main-page-favourites-tab-title = Favourites
main-page-people-tab-title = People
main-page-rooms-tab-title = Rooms
+main-page-room-filter-prompt = Filter rooms by...
room-list-view-room-item-title-name = { $name }
room-list-view-room-item-title-heroes = { $hero } { $otherNum ->
diff --git a/src/matrix-room-list.hpp b/src/matrix-room-list.hpp
--- a/src/matrix-room-list.hpp
+++ b/src/matrix-room-list.hpp
@@ -14,6 +14,7 @@
#include <QAbstractListModel>
#include <lager/sensor.hpp>
+#include <lager/state.hpp>
#include <lager/extra/qt.hpp>
#include <client/client.hpp>
@@ -30,14 +31,16 @@
QString m_tagId;
lager::sensor<std::string> m_tagIdCursor;
int m_internalCount;
+ lager::state<std::string, lager::automatic_tag> m_filter;
lager::reader<immer::flex_vector<std::string>> m_roomIds;
public:
- explicit MatrixRoomList(Kazv::Client client, QString tagId = QString(), QObject *parent = 0);
+ explicit MatrixRoomList(Kazv::Client client, QString tagId = QString(), QString filter = QString(), QObject *parent = 0);
~MatrixRoomList() override;
Q_INVOKABLE void setTagId(QString tagId);
+ LAGER_QT_CURSOR(QString, filter);
LAGER_QT_READER(int, count);
LAGER_QT_READER(QStringList, roomIds);
diff --git a/src/matrix-room-list.cpp b/src/matrix-room-list.cpp
--- a/src/matrix-room-list.cpp
+++ b/src/matrix-room-list.cpp
@@ -29,18 +29,37 @@
return latestEvent.originServerTs();
}
-MatrixRoomList::MatrixRoomList(Kazv::Client client, QString tagId, QObject *parent)
+MatrixRoomList::MatrixRoomList(Kazv::Client client, QString tagId, QString filter, QObject *parent)
: QAbstractListModel(parent)
, m_client(client)
, m_tagId(tagId)
, m_tagIdCursor(lager::make_sensor([this] { return m_tagId.toStdString(); }))
, m_internalCount(0)
- , m_roomIds(lager::with(m_tagIdCursor, m_client.rooms(), m_client.roomIdsByTagId())
- .map([](const auto &tagIdStdStr, const auto &allRooms, const auto &roomsByTagMap) {
+ , m_filter(lager::make_state(filter.toStdString(), lager::automatic_tag{}))
+ , m_roomIds(lager::with(m_tagIdCursor, m_client.rooms(), m_filter, m_client.roomIdsByTagId())
+ .map([](const auto &tagIdStdStr, const auto &allRooms, const auto &filter, const auto &roomsByTagMap) {
auto toId = zug::map([](const auto &pair) {
return pair.first;
});
+ auto roomName = [](const auto &room) {
+ auto content = room.stateEvents[{"m.room.name", ""}].content().get();
+ if (content.contains("name") && content["name"].is_string()) {
+ return content["name"].template get<std::string>();
+ }
+ return std::string();
+ };
+
+ auto applyFilter = zug::filter([&filter, &allRooms, &roomName](const auto &id) {
+ const auto &room = allRooms[id];
+ auto name = roomName(room);
+ return
+ // Use substring match for name search
+ name.find(filter) != std::string::npos
+ // Use exact match for room id
+ || room.roomId == filter;
+ });
+
auto sortByTimestampDesc = [allRooms](std::vector<std::string> container) {
std::sort(
container.begin(),
@@ -55,16 +74,17 @@
if (tagIdStdStr.empty()) {
return sortByTimestampDesc(zug::into_vector(
- toId,
+ toId | applyFilter,
allRooms
));
} else {
return sortByTimestampDesc(zug::into_vector(
- toId,
+ toId | applyFilter,
roomsByTagMap[tagIdStdStr]
));
}
}))
+ , LAGER_QT(filter)(m_filter.xform(strToQt, qStringToStd))
, LAGER_QT(count)(m_roomIds.xform(containerSize))
, LAGER_QT(roomIds)(m_roomIds.xform(zug::map(
[](auto container) {
diff --git a/src/tests/matrix-room-list-test.cpp b/src/tests/matrix-room-list-test.cpp
--- a/src/tests/matrix-room-list-test.cpp
+++ b/src/tests/matrix-room-list-test.cpp
@@ -32,6 +32,7 @@
void testRoomList();
void testSorted();
void testSortedWithTag();
+ void testFilter();
};
static auto tagEvent = Event{R"({
@@ -134,6 +135,38 @@
QCOMPARE(roomList->roomIdAt(2), QString::fromStdString(room2.roomId));
}
+void MatrixRoomListTest::testFilter()
+{
+ auto model = makeTestModel();
+ model.client = makeClient();
+ auto room1 = makeRoom(
+ withRoomState({makeEvent(withStateKey("") | withEventType("m.room.name") | withEventContent(json{{"name", "some room"}}))})
+ );
+ auto room2 = makeRoom(
+ withRoomState({makeEvent(withStateKey("") | withEventType("m.room.name") | withEventContent(json{{"name", "some other room"}}))})
+ );
+ auto room3 = makeRoom(
+ withRoomId("!some:example.org")
+ );
+
+ withRoom(room1)(model.client);
+ withRoom(room2)(model.client);
+ withRoom(room3)(model.client);
+
+ std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)};
+ auto roomList = toUniquePtr(sdk->roomList());
+ roomList->setfilter("some");
+
+ QCOMPARE(roomList->count(), 2);
+ QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room2.roomId));
+ QCOMPARE(roomList->roomIdAt(1), QString::fromStdString(room1.roomId));
+
+ roomList->setfilter("!some:example.org");
+
+ QCOMPARE(roomList->count(), 1);
+ QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room3.roomId));
+}
+
QTEST_MAIN(MatrixRoomListTest)
#include "matrix-room-list-test.moc"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 11:30 AM (20 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40620
Default Alt Text
D10.1732649452.diff (7 KB)
Attached To
Mode
D10: Support filtering by room name and id
Attached
Detach File
Event Timeline
Log In to Comment