From ca31d01fbfc755c9787f757ca97220a490e46ab2 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 15 Aug 2022 14:02:22 -0400 Subject: [PATCH] Rip out communities support --- CMakeLists.txt | 3 - include/community.h | 83 --------------------------- include/communitylistmodel.h | 28 ---------- include/matrixcore.h | 11 ---- include/room.h | 23 -------- qml.qrc | 2 - qml/Client.qml | 14 +---- qml/Communities.qml | 105 ----------------------------------- qml/Community.qml | 80 -------------------------- qml/Profile.qml | 75 ------------------------- src/communitylistmodel.cpp | 14 ----- src/main.cpp | 4 -- src/matrixcore.cpp | 89 ----------------------------- 13 files changed, 1 insertion(+), 530 deletions(-) delete mode 100644 include/community.h delete mode 100644 include/communitylistmodel.h delete mode 100644 qml/Communities.qml delete mode 100644 qml/Community.qml delete mode 100644 src/communitylistmodel.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 06dbb2e..581308a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,9 +21,6 @@ add_executable(${PROJECT_NAME} include/desktop.h include/membermodel.h src/membermodel.cpp - include/community.h - include/communitylistmodel.h - src/communitylistmodel.cpp src/roomlistsortmodel.cpp include/roomlistsortmodel.h include/emotelistmodel.h diff --git a/include/community.h b/include/community.h deleted file mode 100644 index 9603615..0000000 --- a/include/community.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include -#include -#include - -class Community : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString id READ getId NOTIFY idChanged) - Q_PROPERTY(QString name READ getName NOTIFY nameChanged) - Q_PROPERTY(QString avatar READ getAvatar NOTIFY avatarChanged) - Q_PROPERTY(QString shortDescription READ getShortDescription NOTIFY shortDescriptionChanged) - Q_PROPERTY(QString longDescription READ getLongDescription NOTIFY longDescriptionChanged) - Q_PROPERTY(QString joinState READ getJoinState NOTIFY joinStateChanged) -public: - Community(QObject* parent = nullptr) : QObject(parent) {} - - void setId(const QString& id) { - this->id = id; - emit idChanged(); - } - - void setName(const QString& name) { - this->name = name; - emit nameChanged(); - } - - void setAvatar(const QString& url) { - avatarURL = url; - emit avatarChanged(); - } - - void setShortDescription(const QString& description) { - shortDescription = description; - emit shortDescriptionChanged(); - } - - void setLongDescription(const QString& description) { - longDescription = description; - emit longDescriptionChanged(); - } - - void setJoinState(const QString& state) { - joinState = state; - emit joinStateChanged(); - } - - QString getId() const { - return id; - } - - QString getName() const { - return name; - } - - QString getAvatar() const { - return avatarURL; - } - - QString getShortDescription() const { - return shortDescription; - } - - QString getLongDescription() const { - return longDescription; - } - - QString getJoinState() const { - return joinState; - } - -signals: - void idChanged(); - void nameChanged(); - void avatarChanged(); - void shortDescriptionChanged(); - void longDescriptionChanged(); - void joinStateChanged(); - -private: - QString id, name, avatarURL, shortDescription, longDescription, joinState; -}; diff --git a/include/communitylistmodel.h b/include/communitylistmodel.h deleted file mode 100644 index 58a4c1a..0000000 --- a/include/communitylistmodel.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -class Community; - -class CommunityListModel : public QAbstractListModel -{ - Q_OBJECT - Q_PROPERTY(QVariantList communities WRITE setCommunities) -public: - int rowCount(const QModelIndex &parent) const override; - - QVariant data(const QModelIndex &index, int role) const override; - - void setCommunities(const QVariantList& list) { - communities.clear(); - - for(const auto& value : list) - communities.push_back(qvariant_cast(value)); - - emit layoutChanged(); - } - -protected: - QList communities; -}; diff --git a/include/matrixcore.h b/include/matrixcore.h index 65eddcb..3d76e3e 100755 --- a/include/matrixcore.h +++ b/include/matrixcore.h @@ -28,7 +28,6 @@ class MatrixCore : public QObject Q_PROPERTY(QString homeserverURL READ getHomeserverURL NOTIFY homeserverChanged) Q_PROPERTY(MemberListSortModel* memberModel READ getMemberModel NOTIFY currentRoomChanged) Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged) - Q_PROPERTY(QVariantList joinedCommunities READ getJoinedCommunitiesList NOTIFY joinedCommunitiesChanged) Q_PROPERTY(RoomListSortModel* publicRooms READ getDirectoryListModel NOTIFY publicRoomsChanged) Q_PROPERTY(QString typingText READ getTypingText NOTIFY typingTextChanged) Q_PROPERTY(bool markdownEnabled READ getMarkdownEnabled WRITE setMarkdownEnabled NOTIFY markdownEnabledChanged) @@ -69,9 +68,6 @@ public: Q_INVOKABLE void updateMembers(Room* room); Q_INVOKABLE void readMessageHistory(Room* room); - // member - Q_INVOKABLE void updateMemberCommunities(Member* member); - // client related Q_INVOKABLE bool settingsValid(); @@ -84,7 +80,6 @@ public: Q_INVOKABLE void deleteEmote(Emote* emote); Q_INVOKABLE Member* resolveMemberId(const QString& id) const; - Q_INVOKABLE Community* resolveCommunityId(const QString& id) const; Q_INVOKABLE Room* resolveRoomId(const QString& id) const; Q_INVOKABLE Room* getRoom(const unsigned int index) const; @@ -118,8 +113,6 @@ public: QString getHomeserverURL() const; - QVariantList getJoinedCommunitiesList() const; - QString getTypingText() const; bool getMarkdownEnabled() const; @@ -146,7 +139,6 @@ signals: void message(Room* room, QString sender, QString content); void homeserverChanged(bool valid, QString description); void displayNameChanged(); - void joinedCommunitiesChanged(); void publicRoomsChanged(); void typingTextChanged(); void markdownEnabledChanged(); @@ -155,7 +147,6 @@ signals: private: void consumeEvent(const QJsonObject& event, Room& room, const bool insertFront = true); void populateEvent(const QJsonObject& event, Event* e); - Community* createCommunity(const QString& id); QString getMXCThumbnailURL(QString url); QString getMXCMediaURL(QString url); @@ -170,13 +161,11 @@ private: QList invitedRooms, joinedRooms; QList publicRooms; - QList joinedCommunities; QList joinedCommunitiesIds; QList unsentMessages; QMap idToMember; - QMap idToCommunity; QMap idToRoom; QString typingText; diff --git a/include/room.h b/include/room.h index 3f62d8a..7e6ea3e 100755 --- a/include/room.h +++ b/include/room.h @@ -5,8 +5,6 @@ #include #include -#include "community.h" - class EncryptionInformation : public QObject { Q_OBJECT public: @@ -138,7 +136,6 @@ class Member : public QObject { Q_PROPERTY(QString id READ getId NOTIFY idChanged) Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged) Q_PROPERTY(QString avatarURL READ getAvatar NOTIFY avatarChanged) - Q_PROPERTY(QVariantList publicCommunities READ getPublicCommunitiesList NOTIFY publicCommunitiesChanged) public: Member(QObject* parent = nullptr) : QObject(parent) {} @@ -157,11 +154,6 @@ public: emit avatarChanged(); } - void addCommunity(Community* community) { - publicCommunities.push_back(community); - emit publicCommunitiesChanged(); - } - QString getId() const { return id; } @@ -174,28 +166,13 @@ public: return avatarURL; } - QList getPublicCommunities() const { - return publicCommunities; - } - - QVariantList getPublicCommunitiesList() const { - QVariantList list; - for(const auto community : publicCommunities) - list.push_back(QVariant::fromValue(community)); - - return list; - } - signals: void idChanged(); void displayNameChanged(); void avatarChanged(); - void publicCommunitiesChanged(); private: QString id, displayName, avatarURL; - - QList publicCommunities; }; class Room : public QObject diff --git a/qml.qrc b/qml.qrc index 4553b8f..12975fc 100755 --- a/qml.qrc +++ b/qml.qrc @@ -9,10 +9,8 @@ qml/Settings.qml qml/RoomSettings.qml qml/Profile.qml - qml/Community.qml qml/ToolBarButton.qml qml/RoundedImage.qml - qml/Communities.qml qml/Directory.qml qml/InviteDialog.qml qml/BackButton.qml diff --git a/qml/Client.qml b/qml/Client.qml index 15ac773..cd0a4f7 100755 --- a/qml/Client.qml +++ b/qml/Client.qml @@ -307,24 +307,12 @@ Rectangle { onClicked: app.addAccount("test") } - Button { - id: communitiesButton - - width: parent.width - - anchors.bottom: parent.bottom - - text: "Communities" - - onClicked: stack.push("qrc:/Communities.qml") - } - Button { id: directoryButton width: parent.width - anchors.bottom: communitiesButton.top + anchors.bottom: parent.bottom text: "Directory" diff --git a/qml/Communities.qml b/qml/Communities.qml deleted file mode 100644 index 6881f9a..0000000 --- a/qml/Communities.qml +++ /dev/null @@ -1,105 +0,0 @@ -import QtQuick 2.10 -import QtQuick.Controls 2.3 -import QtGraphicalEffects 1.0 -import QtQuick.Shapes 1.0 - -import trinity.matrix 1.0 - -Rectangle { - id: accountCreation - - color: Qt.rgba(0.1, 0.1, 0.1, 1.0) - - Rectangle { - width: 700 - height: parent.height - - anchors.horizontalCenter: parent.horizontalCenter - - color: "transparent" - - BackButton { - id: backButton - - anchors.top: parent.top - anchors.topMargin: 15 - - anchors.right: parent.right - } - - Text { - id: communitiesLabel - - anchors.top: parent.top - anchors.topMargin: 15 - - text: "Communities" - - font.pointSize: 25 - font.bold: true - - color: "white" - } - - Text { - id: joinedCommunitiesLabel - - anchors.top: communitiesLabel.bottom - anchors.topMargin: 10 - - text: "Joined Communities" - - color: "white" - } - - ListView { - id: joinedCommunitiesList - - width: parent.width - - anchors.top: joinedCommunitiesLabel.bottom - - model: CommunityListModel { - communities: matrix.joinedCommunities - } - - delegate: Rectangle { - width: parent.width - height: 60 - - color: "transparent" - - Image { - id: communityAvatar - - width: 32 - height: 32 - - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.leftMargin: 10 - - source: display.avatar - } - - Text { - anchors.left: communityAvatar.right - anchors.leftMargin: 10 - anchors.verticalCenter: parent.verticalCenter - - text: display.name - - color: "white" - } - - MouseArea { - anchors.fill: parent - - onReleased: { - stack.push("qrc:/Community.qml", {"community": matrix.resolveCommunityId(display.id)}) - } - } - } - } - } -} diff --git a/qml/Community.qml b/qml/Community.qml deleted file mode 100644 index d5b7bdc..0000000 --- a/qml/Community.qml +++ /dev/null @@ -1,80 +0,0 @@ -import QtQuick 2.10 -import QtQuick.Controls 2.3 -import QtGraphicalEffects 1.0 -import QtQuick.Shapes 1.0 - -Rectangle { - id: communityDescription - - color: Qt.rgba(0.1, 0.1, 0.1, 1.0) - - property var community - - Rectangle { - width: 700 - height: parent.height - - anchors.horizontalCenter: parent.horizontalCenter - - color: "transparent" - - Button { - id: backButton - - text: "Back" - onClicked: stack.pop() - } - - Image { - id: communityAvatar - - anchors.top: backButton.bottom - anchors.topMargin: 15 - - width: 64 - height: 64 - - source: community.avatar - } - - Text { - id: communityNameLabel - - anchors.left: communityAvatar.right - anchors.leftMargin: 10 - anchors.verticalCenter: communityAvatar.verticalCenter - - text: community.name - - color: "white" - - font.pointSize: 25 - } - - Text { - id: communityShortDescriptionLabel - - anchors.top: communityAvatar.bottom - anchors.topMargin: 15 - - text: community.shortDescription - - color: "gray" - } - - Text { - id: communityLongDescriptionLabel - - width: parent.width - - anchors.top: communityShortDescriptionLabel.bottom - anchors.topMargin: 15 - - text: community.longDescription - - wrapMode: Text.WrapAnywhere - - color: "white" - } - } -} diff --git a/qml/Profile.qml b/qml/Profile.qml index 8423825..962b5b4 100755 --- a/qml/Profile.qml +++ b/qml/Profile.qml @@ -16,7 +16,6 @@ Popup { property var member - Component.onCompleted: matrix.updateMemberCommunities(member) RoundedImage { id: profileAvatar @@ -98,10 +97,6 @@ Popup { text: "Security" } - TabButton { - text: "Communities" - } - TabButton { text: "Sessions" } @@ -117,76 +112,6 @@ Popup { currentIndex: profileTabs.currentIndex - Item { - id: communityTab - - ListView { - id: communityList - - anchors.fill: parent - - model: CommunityListModel { - communities: member.publicCommunities - } - - delegate: Rectangle { - width: parent.width - height: 60 - - color: "transparent" - - RoundedImage { - id: communityAvatar - - width: 32 - height: 32 - - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.leftMargin: 10 - - source: display.avatar - } - - Text { - anchors.left: communityAvatar.right - anchors.leftMargin: 10 - anchors.verticalCenter: parent.verticalCenter - - text: display.name - - color: myPalette.text - } - - MouseArea { - anchors.fill: parent - - onReleased: { - profilePopup.close() - stack.push("qrc:/Community.qml", {"community": matrix.resolveCommunityId(display.id)}) - } - } - } - } - - Rectangle { - anchors.fill: communityList - - color: "transparent" - - Text { - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - - text: "This member does not have any public communities." - - color: myPalette.text - - visible: !member.publicCommunities || member.publicCommunities.length == 0 - } - } - } - Item { id: sessionsTab } diff --git a/src/communitylistmodel.cpp b/src/communitylistmodel.cpp deleted file mode 100644 index b7baf2d..0000000 --- a/src/communitylistmodel.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "communitylistmodel.h" - -#include "community.h" - -int CommunityListModel::rowCount(const QModelIndex &parent) const { - return communities.size(); -} - -QVariant CommunityListModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) - return QVariant::fromValue(communities.at(index.row())); - - return QVariant(); -} diff --git a/src/main.cpp b/src/main.cpp index 3bf98f5..1c5ed6d 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,8 +16,6 @@ #include "matrixcore.h" #include "network.h" #include "desktop.h" -#include "communitylistmodel.h" -#include "community.h" #include "roomlistsortmodel.h" #include "emote.h" #include "appcore.h" @@ -77,9 +75,7 @@ int main(int argc, char* argv[]) { qmlRegisterUncreatableType("trinity.matrix", 1, 0, "Room", ""); qmlRegisterUncreatableType("trinity.matrix", 1, 0, "Event", ""); qmlRegisterUncreatableType("trinity.matrix", 1, 0, "Member", ""); - qmlRegisterUncreatableType("trinity.matrix", 1, 0, "Community", ""); qmlRegisterUncreatableType("trinity.matrix", 1, 0, "Emote", ""); - qmlRegisterType("trinity.matrix", 1, 0, "CommunityListModel"); // platform qmlRegisterUncreatableType("trinity.platform.desktop", 1, 0, "Desktop", ""); diff --git a/src/matrixcore.cpp b/src/matrixcore.cpp index a3f2036..9ac13c3 100755 --- a/src/matrixcore.cpp +++ b/src/matrixcore.cpp @@ -13,7 +13,6 @@ #include #include #include "network.h" -#include "community.h" MatrixCore::MatrixCore(QString profileName, QObject* parent) : QObject(parent), profileName(profileName), roomListModel(rooms), directoryListModel(publicRooms), eventModel(*this) { network = new Network(); @@ -539,23 +538,6 @@ void MatrixCore::sync() { i++; } - for(const auto& id : document.object()["groups"].toObject()["join"].toObject().keys()) { - if(!joinedCommunitiesIds.count(id)) { - Community* community = nullptr; - if(!idToCommunity.count(id)) - community = createCommunity(id); - else - community = idToCommunity[id]; - - community->setJoinState("Joined"); - - joinedCommunities.push_back(community); - joinedCommunitiesIds.push_back(community->getId()); - - emit joinedCommunitiesChanged(); - } - } - if(firstSync) { firstSync = false; emit initialSyncFinished(); @@ -904,41 +886,6 @@ void MatrixCore::readMessageHistory(Room* room) { }); } -void MatrixCore::updateMemberCommunities(Member* member) { - if(!member) - return; - - const QJsonArray userIdsArray { - {member->getId()} - }; - - const QJsonObject userIdsObject { - {"user_ids", userIdsArray} - }; - - network->postJSON("/_matrix/client/r0/publicised_groups", userIdsObject, [this, member](QNetworkReply* reply) { - const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); - - for(const auto id : document.object()["users"].toObject()[member->getId()].toArray()) { - bool found = false; - for(const auto community : member->getPublicCommunities()) { - if(community->getId() == id.toString()) - found = true; - } - - if(!found) { - Community* community = nullptr; - if(!idToCommunity.count(id.toString())) - community = createCommunity(id.toString()); - else - community = idToCommunity[id.toString()]; - - member->addCommunity(community); - } - } - }); -} - bool MatrixCore::settingsValid() { return !network->accessToken.isEmpty() && !network->homeserverURL.isEmpty(); } @@ -1024,9 +971,6 @@ Member* MatrixCore::resolveMemberId(const QString& id) const { return idToMember.value(id); } -Community* MatrixCore::resolveCommunityId(const QString &id) const { - return idToCommunity.value(id); -} Room* MatrixCore::resolveRoomId(const QString &id) const { return idToRoom.value(id); @@ -1310,31 +1254,6 @@ void MatrixCore::populateEvent(const QJsonObject& event, Event* e) { e->setMsg(msg); } -Community* MatrixCore::createCommunity(const QString& id) { - Community* community = new Community(this); - community->setId(id); - - network->get("/_matrix/client/r0/groups/" + community->getId() + "/summary", [this, community](QNetworkReply* reply) { - const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); - - const QJsonObject& profile = document.object()["profile"].toObject(); - - community->setName(profile["name"].toString()); - - if(!profile["avatar_url"].isNull()) { - const QString imageId = profile["avatar_url"].toString().remove("mxc://"); - community->setAvatar(network->homeserverURL + "/_matrix/media/r0/thumbnail/" + imageId + "?width=64&height=64&method=scale"); - } - - community->setShortDescription(profile["short_description"].toString()); - community->setLongDescription(profile["long_description"].toString()); - - idToCommunity.insert(community->getId(), community); - }); - - return community; -} - QString MatrixCore::getMXCThumbnailURL(QString url) { const QString imageId = url.remove("mxc://"); return network->homeserverURL + "/_matrix/media/r0/thumbnail/" + imageId + "?width=64&height=64&method=scale"; @@ -1349,14 +1268,6 @@ QString MatrixCore::getDisplayName() const { return displayName; } -QVariantList MatrixCore::getJoinedCommunitiesList() const { - QVariantList list; - for(const auto community : joinedCommunities) - list.push_back(QVariant::fromValue(community)); - - return list; -} - QString MatrixCore::getTypingText() const { return typingText; }