Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112567
D11.1732335622.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11.1732335622.diff
View Options
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
@@ -50,14 +50,49 @@
return std::string();
};
- auto applyFilter = zug::filter([&filter, &allRooms, &roomName](const auto &id) {
+ auto roomHeroNames = [](const auto &room) {
+ auto heroEvents = room.heroMemberEvents();
+ return intoImmer(
+ immer::flex_vector<std::string>(),
+ zug::map([](const Event &ev) {
+ auto content = ev.content().get();
+ if (content.contains("displayname") && content["displayname"].is_string()) {
+ return content["displayname"].template get<std::string>();
+ }
+ return std::string();
+ }),
+ heroEvents
+ );
+ };
+
+ auto applyFilter = zug::filter([&filter, &allRooms, &roomName, &roomHeroNames](const auto &id) {
+ if (filter.empty()) {
+ return true;
+ }
+
const auto &room = allRooms[id];
+ // Use exact match for room id
+ if (room.roomId == filter) {
+ return true;
+ }
+
auto name = roomName(room);
- return
+ if (!name.empty()) {
// Use substring match for name search
- name.find(filter) != std::string::npos
- // Use exact match for room id
- || room.roomId == filter;
+ return name.find(filter) != std::string::npos;
+ }
+
+ // The room has no name, use hero names for the search
+ auto heroes = roomHeroNames(room);
+ // If any of the room hero matches the filter, consider it a match
+ return std::any_of(heroes.begin(), heroes.end(),
+ [&filter](const auto &name) {
+ return name.find(filter) != std::string::npos;
+ })
+ || std::any_of(room.heroIds.begin(), room.heroIds.end(),
+ [&filter](const auto &id) {
+ return id.find(filter) != std::string::npos;
+ });
});
auto sortByTimestampDesc = [allRooms](std::vector<std::string> 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
@@ -147,7 +147,12 @@
);
auto room3 = makeRoom(
withRoomId("!some:example.org")
+ | withRoomState({
+ makeMemberEvent(withStateKey("@foo:tusooa.xyz") | withEventKV(json::json_pointer("/content/displayname"), "User aaa")),
+ makeMemberEvent(withStateKey("@bar:tusooa.xyz") | withEventKV(json::json_pointer("/content/displayname"), "User bbb")),
+ })
);
+ room3.heroIds = immer::flex_vector<std::string>{"@foo:tusooa.xyz", "@bar:tusooa.xyz"};
withRoom(room1)(model.client);
withRoom(room2)(model.client);
@@ -165,6 +170,16 @@
QCOMPARE(roomList->count(), 1);
QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room3.roomId));
+
+ roomList->setfilter("foo");
+
+ QCOMPARE(roomList->count(), 1);
+ QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room3.roomId));
+
+ roomList->setfilter("aaa");
+
+ QCOMPARE(roomList->count(), 1);
+ QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room3.roomId));
}
QTEST_MAIN(MatrixRoomListTest)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 8:20 PM (3 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39070
Default Alt Text
D11.1732335622.diff (3 KB)
Attached To
Mode
D11: Support filtering unnamed rooms by heros
Attached
Detach File
Event Timeline
Log In to Comment