File tree Expand file tree Collapse file tree 6 files changed +23
-0
lines changed Expand file tree Collapse file tree 6 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1302,6 +1302,8 @@ void Connection::removeFromIgnoredUsers(const QString& userId)
13021302 }
13031303}
13041304
1305+ QStringList Connection::userIds () const { return d->userMap .keys (); }
1306+
13051307const ConnectionData* Connection::connectionData () const
13061308{
13071309 return d->data .get ();
Original file line number Diff line number Diff line change @@ -283,6 +283,11 @@ class QUOTIENT_API Connection : public QObject {
283283 // ! \sa ignoredUsersListChanged
284284 Q_INVOKABLE void removeFromIgnoredUsers (const QString& userId);
285285
286+ // ! \brief Get the entire list of users known to the current user on this homeserver
287+ // ! \note Be mindful that this can easily count thousands or tens of thousands, and use
288+ // ! sparingly; when in a room context, always use Room::members() instead
289+ Q_INVOKABLE QStringList userIds () const ;
290+
286291 // ! Get the base URL of the homeserver to connect to
287292 QUrl homeserver () const ;
288293 // ! Get the domain name used for ids/aliases on the server
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ class Q_DECL_HIDDEN Quotient::Connection::Private {
3939 QHash<QString, QString> roomAliasMap;
4040 QVector<QString> roomIdsToForget;
4141 QVector<QString> pendingStateRoomIds;
42+ // It's an ordered map to make Connection::userIds() return an already sorted list
4243 QMap<QString, User*> userMap;
4344 std::unordered_map<QString, Avatar> userAvatarMap;
4445 DirectChatsMap directChats;
Original file line number Diff line number Diff line change @@ -128,6 +128,12 @@ int Quotient::minorVersion()
128128
129129int Quotient::patchVersion () { return Quotient_VERSION_PATCH; }
130130
131+ bool Quotient::isGuestUserId (const UserId& uId)
132+ {
133+ static const QRegularExpression guestMxIdRe{ QStringLiteral (" ^@\\ d+:" ) };
134+ return guestMxIdRe.match (uId).hasMatch ();
135+ }
136+
131137bool Quotient::HomeserverData::checkMatrixSpecVersion (QStringView targetVersion) const
132138{
133139 // TODO: Replace this naïve implementation with something smarter that can check things like
Original file line number Diff line number Diff line change @@ -429,6 +429,8 @@ using UserId = QString;
429429using RoomId = QString;
430430using EventId = QString;
431431
432+ QUOTIENT_API bool isGuestUserId (const UserId& uId);
433+
432434struct QUOTIENT_API HomeserverData {
433435 QUrl baseUrl;
434436 QStringList supportedSpecVersions;
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class TestUtils : public QObject {
2525 Q_OBJECT
2626private Q_SLOTS:
2727 void testLinkifyUrl ();
28+ void testIsGuestUserId ();
2829
2930private:
3031 void testLinkified (QString original, const QString& expected, const int sourceLine) const
@@ -69,5 +70,11 @@ void TestUtils::testLinkifyUrl()
6970#undef T
7071}
7172
73+ void TestUtils::testIsGuestUserId ()
74+ {
75+ QVERIFY (isGuestUserId (" @123:example.org" _ls));
76+ QVERIFY (!isGuestUserId (" @normal:example.org" _ls));
77+ }
78+
7279QTEST_APPLESS_MAIN (TestUtils)
7380#include " utiltests.moc"
You can’t perform that action at this time.
0 commit comments