Changeset View
Changeset View
Standalone View
Standalone View
src/matrix-room-list.cpp
| Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | , m_roomIds(lager::with(m_tagIdCursor, m_client.rooms(), m_filter, m_client.roomIdsByTagId()) | ||||
| auto roomName = [](const auto &room) { | auto roomName = [](const auto &room) { | ||||
| auto content = room.stateEvents[{"m.room.name", ""}].content().get(); | auto content = room.stateEvents[{"m.room.name", ""}].content().get(); | ||||
| if (content.contains("name") && content["name"].is_string()) { | if (content.contains("name") && content["name"].is_string()) { | ||||
| return content["name"].template get<std::string>(); | return content["name"].template get<std::string>(); | ||||
| } | } | ||||
| return std::string(); | 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]; | const auto &room = allRooms[id]; | ||||
| // Use exact match for room id | |||||
| if (room.roomId == filter) { | |||||
| return true; | |||||
| } | |||||
| auto name = roomName(room); | auto name = roomName(room); | ||||
| return | if (!name.empty()) { | ||||
| // Use substring match for name search | // Use substring match for name search | ||||
| name.find(filter) != std::string::npos | return name.find(filter) != std::string::npos; | ||||
| // Use exact match for room id | } | ||||
| || room.roomId == filter; | |||||
| // 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) { | auto sortByTimestampDesc = [allRooms](std::vector<std::string> container) { | ||||
| std::sort( | std::sort( | ||||
| container.begin(), | container.begin(), | ||||
| container.end(), | container.end(), | ||||
| [allRooms](const std::string &idA, const std::string &idB) { | [allRooms](const std::string &idA, const std::string &idB) { | ||||
| return latestEventTimestamp(allRooms[idA]) | return latestEventTimestamp(allRooms[idA]) | ||||
| ▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines | |||||