Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116592
D82.1733029601.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
D82.1733029601.diff
View Options
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
@@ -16,8 +16,10 @@
#include <lager/extra/qt.hpp>
#include <client/client.hpp>
+Q_MOC_INCLUDE("matrix-user-given-attrs-map.hpp")
class MatrixRoom;
+class MatrixUserGivenAttrsMap;
class MatrixRoomList : public QAbstractListModel
{
@@ -30,6 +32,7 @@
lager::sensor<std::string> m_tagIdCursor;
int m_internalCount;
lager::state<std::string, lager::automatic_tag> m_filter;
+ lager::reader<Kazv::JsonWrap> m_userGivenNicknameMap;
lager::reader<immer::flex_vector<std::string>> m_roomIds;
public:
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
@@ -1,19 +1,21 @@
/*
* This file is part of kazv.
- * SPDX-FileCopyrightText: 2020 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <kazv-defs.hpp>
#include <zug/into_vector.hpp>
+#include <zug/transducer/cat.hpp>
#include <lager/commit.hpp>
#include <lager/constant.hpp>
#include <lager/lenses/optional.hpp>
#include "matrix-room-list.hpp"
#include "matrix-room.hpp"
-
+#include "matrix-user-given-attrs-map.hpp"
+#include "matrix-utils.hpp"
#include "helper.hpp"
using namespace Kazv;
@@ -35,8 +37,9 @@
, m_tagIdCursor(lager::make_sensor([this] { return m_tagId.toStdString(); }))
, m_internalCount(0)
, 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) {
+ , m_userGivenNicknameMap(userGivenNicknameMapFor(m_client).map(&Event::content))
+ , m_roomIds(lager::with(m_tagIdCursor, m_client.rooms(), m_filter, m_client.roomIdsByTagId(), m_userGivenNicknameMap)
+ .map([](const auto &tagIdStdStr, const auto &allRooms, const auto &filter, const auto &roomsByTagMap, const auto &userGivenNicknameMap) {
auto toId = zug::map([](const auto &pair) {
return pair.first;
});
@@ -49,17 +52,24 @@
return std::string();
};
- auto roomHeroNames = [](const auto &room) {
+ auto roomHeroNames = [m=userGivenNicknameMap](const auto &room) {
auto heroEvents = room.heroMemberEvents();
return intoImmer(
immer::flex_vector<std::string>(),
- zug::map([](const Event &ev) {
+ zug::map([m](const Event &ev) {
+ auto userId = ev.stateKey();
auto content = ev.content().get();
+ auto res = std::vector<std::string>{};
if (content.contains("displayname") && content["displayname"].is_string()) {
- return content["displayname"].template get<std::string>();
+ res.push_back(content["displayname"].template get<std::string>());
+ }
+ if (m.get().contains(userId)
+ && m.get()[userId].is_string()) {
+ res.push_back(m.get()[userId].template get<std::string>());
}
- return std::string();
- }),
+ return res;
+ })
+ | zug::cat,
heroEvents
);
};
diff --git a/src/matrix-sdk.hpp b/src/matrix-sdk.hpp
--- a/src/matrix-sdk.hpp
+++ b/src/matrix-sdk.hpp
@@ -226,7 +226,7 @@
*/
MatrixPromise *updateStickerPack(MatrixStickerPackSource source);
- MatrixUserGivenAttrsMap *userGivenNicknameMap();
+ MatrixUserGivenAttrsMap *userGivenNicknameMap() const;
private:
MatrixPromise *sendAccountDataImpl(Kazv::Event event);
diff --git a/src/matrix-sdk.cpp b/src/matrix-sdk.cpp
--- a/src/matrix-sdk.cpp
+++ b/src/matrix-sdk.cpp
@@ -43,13 +43,9 @@
#include "matrix-sticker-pack-list.hpp"
#include "matrix-user-given-attrs-map.hpp"
#include "kazv-log.hpp"
-
+#include "matrix-utils.hpp"
using namespace Kazv;
-static const auto USER_GIVEN_NICKNAME_EVENT_TYPES = immer::array<std::string>{
- "work.banananet.msc3865.user_given.user.displayname"
-};
-
// Sdk with qt event loop, identity transform and no enhancers
using SdkT =
decltype(makeSdk(
@@ -633,18 +629,10 @@
}
}
-MatrixUserGivenAttrsMap *MatrixSdk::userGivenNicknameMap()
+MatrixUserGivenAttrsMap *MatrixSdk::userGivenNicknameMap() const
{
return new MatrixUserGivenAttrsMap(
- m_d->clientOnSecondaryRoot.accountData()
- .map([](const auto &accountData) {
- for (const auto &type : USER_GIVEN_NICKNAME_EVENT_TYPES) {
- if (accountData.count(type) > 0) {
- return accountData[type];
- }
- }
- return Event();
- }),
+ userGivenNicknameMapFor(m_d->clientOnSecondaryRoot),
[client=m_d->clientOnSecondaryRoot](json content) {
return client.setAccountData(json{
{"type", USER_GIVEN_NICKNAME_EVENT_TYPES[0]},
diff --git a/src/matrix-utils.hpp b/src/matrix-utils.hpp
new file mode 100644
--- /dev/null
+++ b/src/matrix-utils.hpp
@@ -0,0 +1,28 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <kazv-defs.hpp>
+#include <string>
+#include <immer/array.hpp>
+#include <client.hpp>
+
+inline const auto USER_GIVEN_NICKNAME_EVENT_TYPES = immer::array<std::string>{
+ "work.banananet.msc3865.user_given.user.displayname"
+};
+
+inline auto userGivenNicknameMapFor(const Kazv::Client &c)
+{
+ return c.accountData()
+ .map([](const auto &accountData) {
+ for (const auto &type : USER_GIVEN_NICKNAME_EVENT_TYPES) {
+ if (accountData.count(type) > 0) {
+ return accountData[type];
+ }
+ }
+ return Kazv::Event();
+ });
+}
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
@@ -15,7 +15,7 @@
#include <matrix-room-list.hpp>
#include <matrix-room.hpp>
#include <matrix-event.hpp>
-
+#include <matrix-utils.hpp>
#include "test-model.hpp"
#include "test-utils.hpp"
#include "factory.hpp"
@@ -168,6 +168,11 @@
withRoom(room1)(model.client);
withRoom(room2)(model.client);
withRoom(room3)(model.client);
+ auto nicknameEvent = makeEvent(
+ withEventType(USER_GIVEN_NICKNAME_EVENT_TYPES[0])
+ | withEventContent(json{{"@foo:tusooa.xyz", "xxxx"}})
+ );
+ withAccountData({ nicknameEvent })(model.client);
std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)};
auto roomList = toUniquePtr(sdk->roomList());
@@ -191,6 +196,12 @@
QCOMPARE(roomList->count(), 1);
QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room3.roomId));
+
+ // By custom nickname of user (@foo:tusooa.xyz)
+ roomList->setfilter("xxxx");
+
+ QCOMPARE(roomList->count(), 1);
+ QCOMPARE(roomList->roomIdAt(0), QString::fromStdString(room3.roomId));
}
QTEST_MAIN(MatrixRoomListTest)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 9:06 PM (16 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41843
Default Alt Text
D82.1733029601.diff (7 KB)
Attached To
Mode
D82: Filter rooms by custom nicknames of room heroes
Attached
Detach File
Event Timeline
Log In to Comment