summary refs log tree commit diff
path: root/src/CommunitiesList.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-14 12:08:16 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-14 12:08:16 +0300
commit73dbd3c8dd78b41c8d93392eac74231e5b4a20d5 (patch)
tree8f48775d63a917faacfff03a55b1767bfb75477a /src/CommunitiesList.cc
parentProperly display the bottom border on the TopRoomBar (diff)
downloadnheko-73dbd3c8dd78b41c8d93392eac74231e5b4a20d5.tar.xz
Re-enable groups
Diffstat (limited to 'src/CommunitiesList.cc')
-rw-r--r--src/CommunitiesList.cc80
1 files changed, 60 insertions, 20 deletions
diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc

index 39e9a7fe..b2742f59 100644 --- a/src/CommunitiesList.cc +++ b/src/CommunitiesList.cc
@@ -40,50 +40,81 @@ CommunitiesList::CommunitiesList(QWidget *parent) scrollArea_->setWidget(scrollAreaContents_); topLayout_->addWidget(scrollArea_); - // connect(http::client(), - // &MatrixClient::communityProfileRetrieved, - // this, - // [this](QString communityId, QJsonObject profile) { - // fetchCommunityAvatar(communityId, profile["avatar_url"].toString()); - // }); connect( this, &CommunitiesList::avatarRetrieved, this, &CommunitiesList::updateCommunityAvatar); } void -CommunitiesList::setCommunities(const std::map<QString, QSharedPointer<Community>> &communities) +CommunitiesList::setCommunities(const mtx::responses::JoinedGroups &response) { communities_.clear(); addGlobalItem(); - for (const auto &community : communities) { - addCommunity(community.second, community.first); - - // http::client()->fetchCommunityProfile(community.first); - // http::client()->fetchCommunityRooms(community.first); - } + for (const auto &group : response.groups) + addCommunity(group); communities_["world"]->setPressedState(true); emit communityChanged("world"); } void -CommunitiesList::addCommunity(QSharedPointer<Community> community, const QString &community_id) +CommunitiesList::addCommunity(const std::string &group_id) { - CommunitiesListItem *list_item = - new CommunitiesListItem(community, community_id, scrollArea_); + const auto id = QString::fromStdString(group_id); + + CommunitiesListItem *list_item = new CommunitiesListItem(id, scrollArea_); + communities_.emplace(id, QSharedPointer<CommunitiesListItem>(list_item)); + contentsLayout_->insertWidget(contentsLayout_->count() - 1, list_item); - communities_.emplace(community_id, QSharedPointer<CommunitiesListItem>(list_item)); + connect(this, + &CommunitiesList::groupProfileRetrieved, + this, + [this](const QString &id, const mtx::responses::GroupProfile &profile) { + if (communities_.find(id) == communities_.end()) + return; - fetchCommunityAvatar(community_id, community->getAvatar().toString()); + communities_.at(id)->setName(QString::fromStdString(profile.name)); - contentsLayout_->insertWidget(contentsLayout_->count() - 1, list_item); + if (!profile.avatar_url.empty()) + fetchCommunityAvatar(id, + QString::fromStdString(profile.avatar_url)); + }); + connect(this, + &CommunitiesList::groupRoomsRetrieved, + this, + [this](const QString &id, const std::vector<QString> &rooms) { + if (communities_.find(id) == communities_.end()) + return; + communities_.at(id)->setRooms(rooms); + }); connect(list_item, &CommunitiesListItem::clicked, this, &CommunitiesList::highlightSelectedCommunity); + + http::v2::client()->group_profile( + group_id, [id, this](const mtx::responses::GroupProfile &res, mtx::http::RequestErr err) { + if (err) { + return; + } + + emit groupProfileRetrieved(id, res); + }); + + http::v2::client()->group_rooms( + group_id, [id, this](const nlohmann::json &res, mtx::http::RequestErr err) { + if (err) { + return; + } + + std::vector<QString> room_ids; + for (const auto &room : res.at("chunk")) + room_ids.push_back(QString::fromStdString(room.at("room_id"))); + + emit groupRoomsRetrieved(id, room_ids); + }); } void @@ -94,7 +125,7 @@ CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixma return; } - communities_.find(community_id)->second->setAvatar(img.toImage()); + communities_.at(community_id)->setAvatar(img.toImage()); } void @@ -153,3 +184,12 @@ CommunitiesList::fetchCommunityAvatar(const QString &id, const QString &avatarUr emit avatarRetrieved(id, pix); }); } + +std::vector<QString> +CommunitiesList::roomList(const QString &id) const +{ + if (communityExists(id)) + return communities_.at(id)->rooms(); + + return {}; +}