Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114941
D89.1732594297.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D89.1732594297.diff
View Options
diff --git a/src/matrix-event-reader-list-model.cpp b/src/matrix-event-reader-list-model.cpp
--- a/src/matrix-event-reader-list-model.cpp
+++ b/src/matrix-event-reader-list-model.cpp
@@ -17,6 +17,7 @@
return std::get<0>(item);
}))),
QString(),
+ lager::make_constant(Kazv::Event()),
parent
)
, m_readers(readers)
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
@@ -186,7 +186,11 @@
MatrixRoom *MatrixRoomList::room(QString roomId) const
{
- return new MatrixRoom(m_client.room(roomId.toStdString()), m_client.userId());
+ return new MatrixRoom(
+ m_client.room(roomId.toStdString()),
+ m_client.userId(),
+ userGivenNicknameMapFor(m_client)
+ );
}
QVariant MatrixRoomList::data(const QModelIndex &/* index */, int /* role */) const
diff --git a/src/matrix-room-member-list-model.hpp b/src/matrix-room-member-list-model.hpp
--- a/src/matrix-room-member-list-model.hpp
+++ b/src/matrix-room-member-list-model.hpp
@@ -28,7 +28,7 @@
int m_internalCount;
public:
- explicit MatrixRoomMemberListModel(lager::reader<Kazv::EventList> members, QString filter = QString(), QObject *parent = 0);
+ explicit MatrixRoomMemberListModel(lager::reader<Kazv::EventList> members, QString filter = QString(), lager::reader<Kazv::Event> userGivenNicknameEvent = lager::make_constant(Kazv::Event()), QObject *parent = 0);
~MatrixRoomMemberListModel() override;
LAGER_QT_CURSOR(QString, filter);
diff --git a/src/matrix-room-member-list-model.cpp b/src/matrix-room-member-list-model.cpp
--- a/src/matrix-room-member-list-model.cpp
+++ b/src/matrix-room-member-list-model.cpp
@@ -17,20 +17,31 @@
using namespace Kazv;
-MatrixRoomMemberListModel::MatrixRoomMemberListModel(lager::reader<Kazv::EventList> members, QString filter, QObject *parent)
+MatrixRoomMemberListModel::MatrixRoomMemberListModel(lager::reader<Kazv::EventList> members, QString filter, lager::reader<Kazv::Event> userGivenNicknameEvent, QObject *parent)
: QAbstractListModel(parent)
, m_filter(lager::make_state(filter.toStdString(), lager::automatic_tag{}))
- , m_members(lager::with(members, m_filter).map([](const auto &members, const auto &filter) {
+ , m_members(lager::with(
+ members,
+ m_filter,
+ userGivenNicknameEvent.map(&Event::content)
+ ).map([](const auto &members, const auto &filter, const auto &map) {
if (filter.empty()) {
return members;
}
- return intoImmer(EventList{}, zug::filter([filter](const auto &e) {
+ return intoImmer(EventList{}, zug::filter([filter, map=map.get()](const auto &e) {
auto userId = e.stateKey();
if (userId.find(filter) != std::string::npos) {
return true;
}
+ // user given nickname match
auto content = e.content().get();
+ if (map.contains(userId) && map[userId].is_string()) {
+ auto name = map[userId].template get<std::string>();
+ if (name.find(filter) != std::string::npos) {
+ return true;
+ }
+ }
if (content.contains("displayname")
&& content["displayname"].is_string()) {
auto name = content["displayname"].template get<std::string>();
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -31,6 +31,7 @@
QML_UNCREATABLE("")
Kazv::Room m_room;
+ lager::reader<Kazv::Event> m_userGivenNicknameEvent;
lager::reader<std::string> m_selfUserId;
lager::reader<immer::flex_vector<std::string>> m_memberNames;
lager::reader<Kazv::PowerLevelsDesc> m_powerLevels;
@@ -43,7 +44,7 @@
};
Q_ENUM(Membership);
- explicit MatrixRoom(Kazv::Room room, lager::reader<std::string> selfUserId, QObject *parent = 0);
+ explicit MatrixRoom(Kazv::Room room, lager::reader<std::string> selfUserId, lager::reader<Kazv::Event> userGivenNicknameEvent = lager::make_constant(Kazv::Event()), QObject *parent = 0);
~MatrixRoom() override;
LAGER_QT_READER(QString, roomId);
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -32,9 +32,10 @@
static const int saveDraftDebounceMs = 5000;
static const int typingTimeoutMs = 1000;
-MatrixRoom::MatrixRoom(Kazv::Room room, lager::reader<std::string> selfUserId, QObject *parent)
+MatrixRoom::MatrixRoom(Kazv::Room room, lager::reader<std::string> selfUserId, lager::reader<Kazv::Event> userGivenNicknameEvent, QObject *parent)
: QObject(parent)
, m_room(room)
+ , m_userGivenNicknameEvent(userGivenNicknameEvent)
, m_selfUserId(selfUserId)
, m_memberNames(m_room.members())
, m_powerLevels(m_room.powerLevels())
@@ -407,14 +408,18 @@
MatrixRoomMemberListModel *MatrixRoom::members() const
{
return new MatrixRoomMemberListModel(
- m_room.joinedMemberEvents()
+ m_room.joinedMemberEvents(),
+ QString(),
+ m_userGivenNicknameEvent
);
}
MatrixRoomMemberListModel *MatrixRoom::bannedMembers() const
{
return new MatrixRoomMemberListModel(
- m_room.bannedMemberEvents()
+ m_room.bannedMemberEvents(),
+ QString(),
+ m_userGivenNicknameEvent
);
}
diff --git a/src/tests/matrix-room-member-list-model-test.cpp b/src/tests/matrix-room-member-list-model-test.cpp
--- a/src/tests/matrix-room-member-list-model-test.cpp
+++ b/src/tests/matrix-room-member-list-model-test.cpp
@@ -51,7 +51,13 @@
void MatrixRoomMemberListModelTest::testFilter()
{
- MatrixRoomMemberListModel model(lager::make_constant(data));
+ MatrixRoomMemberListModel model(
+ lager::make_constant(data),
+ QString(),
+ lager::make_constant(Event(json{
+ {"content", {{"@t1:tusooa.xyz", "mewmew"}}},
+ }))
+ );
QCOMPARE(model.count(), 2);
@@ -71,6 +77,13 @@
auto first = toUniquePtr(model.at(0));
QCOMPARE(first->userId(), QString("@t2:tusooa.xyz"));
}
+
+ {
+ model.setfilter(QString("mewmew"));
+ QCOMPARE(model.count(), 1);
+ auto first = toUniquePtr(model.at(0));
+ QCOMPARE(first->userId(), QString("@t1:tusooa.xyz"));
+ }
}
QTEST_MAIN(MatrixRoomMemberListModelTest)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 8:11 PM (12 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40426
Default Alt Text
D89.1732594297.diff (6 KB)
Attached To
Mode
D89: Make completion filterable by overrided nickname
Attached
Detach File
Event Timeline
Log In to Comment