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 +++++++++++++++++++++++++++++++++++++++++++++++ src/ui/UserProfile.h | 27 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) (limited to 'src/ui') 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() { diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index d8423ffa..a880f320 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -119,6 +119,30 @@ private: friend class UserProfile; }; +class RoomInfoModel final : public QAbstractListModel +{ + Q_OBJECT +public: + enum Roles + { + RoomId, + RoomName, + AvatarUrl, + }; + + explicit RoomInfoModel(const std::map &, QObject *parent = nullptr); + QHash roleNames() const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override + { + (void)parent; + return (int)roomInfos_.size(); + } + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +private: + std::vector> roomInfos_; +}; + class UserProfile final : public QObject { Q_OBJECT @@ -126,6 +150,7 @@ class UserProfile final : public QObject Q_PROPERTY(QString userid READ userid CONSTANT) Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged) Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList NOTIFY devicesChanged) + Q_PROPERTY(RoomInfoModel *sharedRooms READ sharedRooms CONSTANT) Q_PROPERTY(bool isGlobalUserProfile READ isGlobalUserProfile CONSTANT) Q_PROPERTY(int userVerified READ getUserStatus NOTIFY userStatusChanged) Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged) @@ -139,6 +164,7 @@ public: TimelineModel *parent = nullptr); DeviceInfoModel *deviceList(); + RoomInfoModel *sharedRooms(); QString userid(); QString displayName(); @@ -198,4 +224,5 @@ private: bool isLoading_ = false; TimelineViewManager *manager; TimelineModel *model; + RoomInfoModel *sharedRooms_ = nullptr; }; -- cgit 1.5.1