diff --git a/include/ChatPage.h b/include/ChatPage.h index 0b1c2deb..773e3bc5 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -26,9 +26,10 @@ #include "MemberEventContent.h" #include "MessageEvent.h" #include "StateEvent.h" +#include "CommunitiesList.h" +#include "Community.h" class Cache; -class CommunitiesList; class MatrixClient; class OverlayModal; class QuickSwitcher; diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index c0fd12ab..e78d3f6e 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -101,39 +101,6 @@ private: int unreadMsgCount_ = 0; }; -inline int -RoomInfoListItem::unreadMessageCount() const -{ - return unreadMsgCount_; -} - -inline bool -RoomInfoListItem::isPressed() const -{ - return isPressed_; -} - -inline RoomState -RoomInfoListItem::state() const -{ - return state_; -} - -inline void -RoomInfoListItem::setAvatar(const QImage &img) -{ - roomAvatar_ = QPixmap::fromImage( - img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - update(); -} - -inline void -RoomInfoListItem::setDescriptionMessage(const DescInfo &info) -{ - lastMsgInfo_ = info; - update(); -} - inline QString RoomInfoListItem::roomId() { diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 0dfb6cd0..1c0658a6 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -476,7 +476,29 @@ MatrixClient::getOwnCommunities() noexcept QNetworkRequest request(QString(endpoint.toEncoded())); QNetworkReply *reply = get(request); - reply->setProperty("endpoint", static_cast<int>(Endpoint::GetOwnCommunities)); + connect(reply, &QNetworkReply::finished, this, [this, reply]() { + reply->deleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (status >= 400) { + qWarning() << reply->errorString(); + return; + } + + auto data = reply->readAll(); + auto json = QJsonDocument::fromJson(data).object(); + + try { + QList<QString> response; + for (auto it = json["groups"].toArray().constBegin(); it != json["groups"].toArray().constEnd(); it++) { + response.append(it->toString()); + } + emit getOwnCommunitiesResponse(response); + } catch (DeserializationException &e) { + qWarning() << "Own communities:" << e.what(); + } + }); } void @@ -526,7 +548,7 @@ MatrixClient::fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url) } void -MatrixClient::fetchCommunityAvatar(const QString &communityid, const QUrl &avatar_url) +MatrixClient::fetchCommunityAvatar(const QString &communityId, const QUrl &avatar_url) { QList<QString> url_parts = avatar_url.toString().split("mxc://"); @@ -585,7 +607,7 @@ MatrixClient::fetchCommunityProfile(const QString &communityId) QNetworkReply *reply = get(request); - connect(reply, &QNetworkRequest::finished, this, [this, reply, communityId]() { + connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -615,7 +637,7 @@ MatrixClient::fetchCommunityRooms(const QString &communityId) QNetworkRequest request(QString(endpoint.toEncoded())); QNetworkReply *reply = get(request); - connect(reply, &QNetworkRequest::finished, this, [this, reply, communityId]() { + connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();