From aae3300860ebe2fac39a156a31f9cddeefb4bf92 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 24 Feb 2023 02:40:14 +0100 Subject: Show rooms you share with someone --- src/ui/UserProfile.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/ui/UserProfile.cpp') diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 66a68bb8..80def409 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -58,6 +58,12 @@ UserProfile::UserProfile(const QString &roomid, emit verificationStatiChanged(); }); fetchDeviceList(this->userid_); + + if (userid != utils::localUser()) + sharedRooms_ = + new RoomInfoModel(cache::client()->getCommonRooms(userid.toStdString()), this); + else + sharedRooms_ = new RoomInfoModel({}, this); } QHash @@ -102,12 +108,53 @@ DeviceInfoModel::reset(const std::vector &deviceList) endResetModel(); } +RoomInfoModel::RoomInfoModel(const std::map &raw, QObject *parent) + : QAbstractListModel(parent) +{ + for (const auto &e : raw) + roomInfos_.push_back(e); +} + +QHash +RoomInfoModel::roleNames() const +{ + return { + {RoomId, "roomId"}, + {RoomName, "roomName"}, + {AvatarUrl, "avatarUrl"}, + }; +} + +QVariant +RoomInfoModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() >= (int)roomInfos_.size() || index.row() < 0) + return {}; + + switch (role) { + case RoomId: + return QString::fromStdString(roomInfos_[index.row()].first); + case RoomName: + return QString::fromStdString(roomInfos_[index.row()].second.name); + case AvatarUrl: + return QString::fromStdString(roomInfos_[index.row()].second.avatar_url); + default: + return {}; + } +} + DeviceInfoModel * UserProfile::deviceList() { return &this->deviceList_; } +RoomInfoModel * +UserProfile::sharedRooms() +{ + return this->sharedRooms_; +} + QString UserProfile::userid() { -- cgit 1.5.1