diff options
Diffstat (limited to 'connection.cpp')
-rw-r--r-- | connection.cpp | 24 |
1 files changed, 24 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; |