aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp24
-rw-r--r--connection.h15
-rw-r--r--room.cpp34
-rw-r--r--room.h9
4 files changed, 82 insertions, 0 deletions
diff --git a/connection.cpp b/connection.cpp
index 4b7d4abb..52fcc40b 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -520,6 +520,30 @@ QHash< QPair<QString, bool>, Room* > Connection::roomMap() const
return roomMap;
}
+QHash<QString, QVector<Room*>> Connection::tagsToRooms() const
+{
+ QHash<QString, QVector<Room*>> result;
+ for (auto* r: d->roomMap)
+ {
+ for (const auto& tagName: r->tagNames())
+ result[tagName].push_back(r);
+ }
+ for (auto it = result.begin(); it != result.end(); ++it)
+ std::sort(it->begin(), it->end(),
+ [t=it.key()] (Room* r1, Room* r2) {
+ return r1->tags().value(t).order < r2->tags().value(t).order;
+ });
+ return result;
+}
+
+QVector<Room*> Connection::roomsWithTag(const QString& tagName) const
+{
+ QVector<Room*> rooms;
+ std::copy_if(d->roomMap.begin(), d->roomMap.end(), std::back_inserter(rooms),
+ [&tagName] (Room* r) { return r->tags().contains(tagName); });
+ return rooms;
+}
+
QMap<QString, User*> Connection::users() const
{
return d->userMap;
diff --git a/connection.h b/connection.h
index 3ec4fd9d..b45a171d 100644
--- a/connection.h
+++ b/connection.h
@@ -70,7 +70,22 @@ namespace QMatrixClient
explicit Connection(const QUrl& server, QObject* parent = nullptr);
virtual ~Connection();
+ /** Get all Invited and Joined rooms
+ * \return a hashmap from a composite key - room name and whether
+ * it's an Invite rather than Join - to room pointers
+ */
QHash<QPair<QString, bool>, Room*> roomMap() const;
+
+ /** Get all Invited and Joined rooms grouped by tag
+ * \return a hashmap from tag name to a vector of room pointers,
+ * sorted by their order in the tag - details are at
+ * https://matrix.org/speculator/spec/drafts%2Fe2e/client_server/unstable.html#id95
+ */
+ QHash<QString, QVector<Room*>> tagsToRooms() const;
+
+ /** Get the list of rooms with the specified tag */
+ QVector<Room*> roomsWithTag(const QString& tagName) const;
+
QMap<QString, User*> users() const;
// FIXME: Convert Q_INVOKABLEs to Q_PROPERTIES
diff --git a/room.cpp b/room.cpp
index 762e929c..29244da2 100644
--- a/room.cpp
+++ b/room.cpp
@@ -95,6 +95,8 @@ class Room::Private
QString firstDisplayedEventId;
QString lastDisplayedEventId;
QHash<const User*, QString> lastReadEventIds;
+ QHash<QString, TagRecord> tags;
+ QHash<QString, QJsonObject> accountData;
QString prevBatch;
QPointer<RoomMessagesJob> roomMessagesJob;
@@ -552,6 +554,16 @@ void Room::resetHighlightCount()
emit highlightCountChanged(this);
}
+QStringList Room::tagNames() const
+{
+ return d->tags.keys();
+}
+
+const QHash<QString, TagRecord>& Room::tags() const
+{
+ return d->tags;
+}
+
const RoomMessageEvent*
Room::Private::getEventWithFile(const QString& eventId) const
{
@@ -873,6 +885,15 @@ void Room::updateData(SyncRoomData&& data)
<< et.elapsed() << "ms";
}
+ if (!data.accountData.empty())
+ {
+ et.restart();
+ for (auto&& event: data.accountData)
+ processAccountDataEvent(move(event));
+ qCDebug(PROFILER) << "*** Room::processAccountData():"
+ << et.elapsed() << "ms";
+ }
+
if( data.highlightCount != d->highlightCount )
{
d->highlightCount = data.highlightCount;
@@ -1433,6 +1454,19 @@ void Room::processEphemeralEvent(EventPtr event)
}
}
+void Room::processAccountDataEvent(EventPtr event)
+{
+ switch (event->type())
+ {
+ case EventType::Tag:
+ d->tags = static_cast<TagEvent*>(event.get())->tags();
+ emit tagsChanged();
+ break;
+ default:
+ d->accountData[event->jsonType()] = event->contentJson();
+ }
+}
+
QString Room::Private::roomNameFromMemberNames(const QList<User *> &userlist) const
{
// This is part 3(i,ii,iii) in the room displayname algorithm described
diff --git a/room.h b/room.h
index 5253a7c6..6dba6156 100644
--- a/room.h
+++ b/room.h
@@ -20,6 +20,7 @@
#include "jobs/syncjob.h"
#include "events/roommessageevent.h"
+#include "events/tagevent.h"
#include "joinstate.h"
#include <QtCore/QList>
@@ -116,6 +117,8 @@ namespace QMatrixClient
Q_PROPERTY(QString lastDisplayedEventId READ lastDisplayedEventId WRITE setLastDisplayedEventId NOTIFY lastDisplayedEventChanged)
Q_PROPERTY(QString readMarkerEventId READ readMarkerEventId WRITE markMessagesAsRead NOTIFY readMarkerMoved)
+ Q_PROPERTY(QStringList tagNames READ tagNames NOTIFY tagsChanged)
+
public:
using Timeline = std::deque<TimelineItem>;
using rev_iter_t = Timeline::const_reverse_iterator;
@@ -237,6 +240,9 @@ namespace QMatrixClient
Q_INVOKABLE int highlightCount() const;
Q_INVOKABLE void resetHighlightCount();
+ QStringList tagNames() const;
+ const QHash<QString, TagRecord>& tags() const;
+
Q_INVOKABLE QUrl urlToThumbnail(const QString& eventId);
Q_INVOKABLE QUrl urlToDownload(const QString& eventId);
Q_INVOKABLE QString fileNameToDownload(const QString& eventId);
@@ -318,6 +324,8 @@ namespace QMatrixClient
void readMarkerMoved();
void unreadMessagesChanged(Room* room);
+ void tagsChanged();
+
void replacedEvent(const RoomEvent* newEvent,
const RoomEvent* oldEvent);
@@ -330,6 +338,7 @@ namespace QMatrixClient
protected:
virtual void processStateEvents(const RoomEvents& events);
virtual void processEphemeralEvent(EventPtr event);
+ virtual void processAccountDataEvent(EventPtr event);
virtual void onAddNewTimelineEvents(timeline_iter_t from) { }
virtual void onAddHistoricalTimelineEvents(rev_iter_t from) { }
virtual void onRedaction(const RoomEvent* prevEvent,