Archived
1
Fork 0

Rip out communities support

This commit is contained in:
Joshua Goins 2022-08-15 14:02:22 -04:00
parent 25564dd5f4
commit ca31d01fbf
13 changed files with 1 additions and 530 deletions

View file

@ -21,9 +21,6 @@ add_executable(${PROJECT_NAME}
include/desktop.h include/desktop.h
include/membermodel.h include/membermodel.h
src/membermodel.cpp src/membermodel.cpp
include/community.h
include/communitylistmodel.h
src/communitylistmodel.cpp
src/roomlistsortmodel.cpp src/roomlistsortmodel.cpp
include/roomlistsortmodel.h include/roomlistsortmodel.h
include/emotelistmodel.h include/emotelistmodel.h

View file

@ -1,83 +0,0 @@
#pragma once
#include <QObject>
#include <QString>
#include <QDebug>
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;
};

View file

@ -1,28 +0,0 @@
#pragma once
#include <QAbstractListModel>
#include <QDebug>
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<Community*>(value));
emit layoutChanged();
}
protected:
QList<Community*> communities;
};

View file

@ -28,7 +28,6 @@ class MatrixCore : public QObject
Q_PROPERTY(QString homeserverURL READ getHomeserverURL NOTIFY homeserverChanged) Q_PROPERTY(QString homeserverURL READ getHomeserverURL NOTIFY homeserverChanged)
Q_PROPERTY(MemberListSortModel* memberModel READ getMemberModel NOTIFY currentRoomChanged) Q_PROPERTY(MemberListSortModel* memberModel READ getMemberModel NOTIFY currentRoomChanged)
Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged) 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(RoomListSortModel* publicRooms READ getDirectoryListModel NOTIFY publicRoomsChanged)
Q_PROPERTY(QString typingText READ getTypingText NOTIFY typingTextChanged) Q_PROPERTY(QString typingText READ getTypingText NOTIFY typingTextChanged)
Q_PROPERTY(bool markdownEnabled READ getMarkdownEnabled WRITE setMarkdownEnabled NOTIFY markdownEnabledChanged) Q_PROPERTY(bool markdownEnabled READ getMarkdownEnabled WRITE setMarkdownEnabled NOTIFY markdownEnabledChanged)
@ -69,9 +68,6 @@ public:
Q_INVOKABLE void updateMembers(Room* room); Q_INVOKABLE void updateMembers(Room* room);
Q_INVOKABLE void readMessageHistory(Room* room); Q_INVOKABLE void readMessageHistory(Room* room);
// member
Q_INVOKABLE void updateMemberCommunities(Member* member);
// client related // client related
Q_INVOKABLE bool settingsValid(); Q_INVOKABLE bool settingsValid();
@ -84,7 +80,6 @@ public:
Q_INVOKABLE void deleteEmote(Emote* emote); Q_INVOKABLE void deleteEmote(Emote* emote);
Q_INVOKABLE Member* resolveMemberId(const QString& id) const; 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* resolveRoomId(const QString& id) const;
Q_INVOKABLE Room* getRoom(const unsigned int index) const; Q_INVOKABLE Room* getRoom(const unsigned int index) const;
@ -118,8 +113,6 @@ public:
QString getHomeserverURL() const; QString getHomeserverURL() const;
QVariantList getJoinedCommunitiesList() const;
QString getTypingText() const; QString getTypingText() const;
bool getMarkdownEnabled() const; bool getMarkdownEnabled() const;
@ -146,7 +139,6 @@ signals:
void message(Room* room, QString sender, QString content); void message(Room* room, QString sender, QString content);
void homeserverChanged(bool valid, QString description); void homeserverChanged(bool valid, QString description);
void displayNameChanged(); void displayNameChanged();
void joinedCommunitiesChanged();
void publicRoomsChanged(); void publicRoomsChanged();
void typingTextChanged(); void typingTextChanged();
void markdownEnabledChanged(); void markdownEnabledChanged();
@ -155,7 +147,6 @@ signals:
private: private:
void consumeEvent(const QJsonObject& event, Room& room, const bool insertFront = true); void consumeEvent(const QJsonObject& event, Room& room, const bool insertFront = true);
void populateEvent(const QJsonObject& event, Event* e); void populateEvent(const QJsonObject& event, Event* e);
Community* createCommunity(const QString& id);
QString getMXCThumbnailURL(QString url); QString getMXCThumbnailURL(QString url);
QString getMXCMediaURL(QString url); QString getMXCMediaURL(QString url);
@ -170,13 +161,11 @@ private:
QList<QString> invitedRooms, joinedRooms; QList<QString> invitedRooms, joinedRooms;
QList<Room*> publicRooms; QList<Room*> publicRooms;
QList<Community*> joinedCommunities;
QList<QString> joinedCommunitiesIds; QList<QString> joinedCommunitiesIds;
QList<Event*> unsentMessages; QList<Event*> unsentMessages;
QMap<QString, Member*> idToMember; QMap<QString, Member*> idToMember;
QMap<QString, Community*> idToCommunity;
QMap<QString, Room*> idToRoom; QMap<QString, Room*> idToRoom;
QString typingText; QString typingText;

View file

@ -5,8 +5,6 @@
#include <QDateTime> #include <QDateTime>
#include <QSettings> #include <QSettings>
#include "community.h"
class EncryptionInformation : public QObject { class EncryptionInformation : public QObject {
Q_OBJECT Q_OBJECT
public: public:
@ -138,7 +136,6 @@ class Member : public QObject {
Q_PROPERTY(QString id READ getId NOTIFY idChanged) Q_PROPERTY(QString id READ getId NOTIFY idChanged)
Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged) Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(QString avatarURL READ getAvatar NOTIFY avatarChanged) Q_PROPERTY(QString avatarURL READ getAvatar NOTIFY avatarChanged)
Q_PROPERTY(QVariantList publicCommunities READ getPublicCommunitiesList NOTIFY publicCommunitiesChanged)
public: public:
Member(QObject* parent = nullptr) : QObject(parent) {} Member(QObject* parent = nullptr) : QObject(parent) {}
@ -157,11 +154,6 @@ public:
emit avatarChanged(); emit avatarChanged();
} }
void addCommunity(Community* community) {
publicCommunities.push_back(community);
emit publicCommunitiesChanged();
}
QString getId() const { QString getId() const {
return id; return id;
} }
@ -174,28 +166,13 @@ public:
return avatarURL; return avatarURL;
} }
QList<Community*> getPublicCommunities() const {
return publicCommunities;
}
QVariantList getPublicCommunitiesList() const {
QVariantList list;
for(const auto community : publicCommunities)
list.push_back(QVariant::fromValue(community));
return list;
}
signals: signals:
void idChanged(); void idChanged();
void displayNameChanged(); void displayNameChanged();
void avatarChanged(); void avatarChanged();
void publicCommunitiesChanged();
private: private:
QString id, displayName, avatarURL; QString id, displayName, avatarURL;
QList<Community*> publicCommunities;
}; };
class Room : public QObject class Room : public QObject

View file

@ -9,10 +9,8 @@
<file alias="Settings.qml">qml/Settings.qml</file> <file alias="Settings.qml">qml/Settings.qml</file>
<file alias="RoomSettings.qml">qml/RoomSettings.qml</file> <file alias="RoomSettings.qml">qml/RoomSettings.qml</file>
<file alias="Profile.qml">qml/Profile.qml</file> <file alias="Profile.qml">qml/Profile.qml</file>
<file alias="Community.qml">qml/Community.qml</file>
<file alias="ToolBarButton.qml">qml/ToolBarButton.qml</file> <file alias="ToolBarButton.qml">qml/ToolBarButton.qml</file>
<file alias="RoundedImage.qml">qml/RoundedImage.qml</file> <file alias="RoundedImage.qml">qml/RoundedImage.qml</file>
<file alias="Communities.qml">qml/Communities.qml</file>
<file alias="Directory.qml">qml/Directory.qml</file> <file alias="Directory.qml">qml/Directory.qml</file>
<file alias="InviteDialog.qml">qml/InviteDialog.qml</file> <file alias="InviteDialog.qml">qml/InviteDialog.qml</file>
<file alias="BackButton.qml">qml/BackButton.qml</file> <file alias="BackButton.qml">qml/BackButton.qml</file>

View file

@ -307,24 +307,12 @@ Rectangle {
onClicked: app.addAccount("test") onClicked: app.addAccount("test")
} }
Button {
id: communitiesButton
width: parent.width
anchors.bottom: parent.bottom
text: "Communities"
onClicked: stack.push("qrc:/Communities.qml")
}
Button { Button {
id: directoryButton id: directoryButton
width: parent.width width: parent.width
anchors.bottom: communitiesButton.top anchors.bottom: parent.bottom
text: "Directory" text: "Directory"

View file

@ -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)})
}
}
}
}
}
}

View file

@ -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"
}
}
}

View file

@ -16,7 +16,6 @@ Popup {
property var member property var member
Component.onCompleted: matrix.updateMemberCommunities(member)
RoundedImage { RoundedImage {
id: profileAvatar id: profileAvatar
@ -98,10 +97,6 @@ Popup {
text: "Security" text: "Security"
} }
TabButton {
text: "Communities"
}
TabButton { TabButton {
text: "Sessions" text: "Sessions"
} }
@ -117,76 +112,6 @@ Popup {
currentIndex: profileTabs.currentIndex 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 { Item {
id: sessionsTab id: sessionsTab
} }

View file

@ -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<Community*>(communities.at(index.row()));
return QVariant();
}

View file

@ -16,8 +16,6 @@
#include "matrixcore.h" #include "matrixcore.h"
#include "network.h" #include "network.h"
#include "desktop.h" #include "desktop.h"
#include "communitylistmodel.h"
#include "community.h"
#include "roomlistsortmodel.h" #include "roomlistsortmodel.h"
#include "emote.h" #include "emote.h"
#include "appcore.h" #include "appcore.h"
@ -77,9 +75,7 @@ int main(int argc, char* argv[]) {
qmlRegisterUncreatableType<Room>("trinity.matrix", 1, 0, "Room", ""); qmlRegisterUncreatableType<Room>("trinity.matrix", 1, 0, "Room", "");
qmlRegisterUncreatableType<Event>("trinity.matrix", 1, 0, "Event", ""); qmlRegisterUncreatableType<Event>("trinity.matrix", 1, 0, "Event", "");
qmlRegisterUncreatableType<Member>("trinity.matrix", 1, 0, "Member", ""); qmlRegisterUncreatableType<Member>("trinity.matrix", 1, 0, "Member", "");
qmlRegisterUncreatableType<Community>("trinity.matrix", 1, 0, "Community", "");
qmlRegisterUncreatableType<Emote>("trinity.matrix", 1, 0, "Emote", ""); qmlRegisterUncreatableType<Emote>("trinity.matrix", 1, 0, "Emote", "");
qmlRegisterType<CommunityListModel>("trinity.matrix", 1, 0, "CommunityListModel");
// platform // platform
qmlRegisterUncreatableType<Desktop>("trinity.platform.desktop", 1, 0, "Desktop", ""); qmlRegisterUncreatableType<Desktop>("trinity.platform.desktop", 1, 0, "Desktop", "");

View file

@ -13,7 +13,6 @@
#include <fstream> #include <fstream>
#include <iterator> #include <iterator>
#include "network.h" #include "network.h"
#include "community.h"
MatrixCore::MatrixCore(QString profileName, QObject* parent) : QObject(parent), profileName(profileName), roomListModel(rooms), directoryListModel(publicRooms), eventModel(*this) { MatrixCore::MatrixCore(QString profileName, QObject* parent) : QObject(parent), profileName(profileName), roomListModel(rooms), directoryListModel(publicRooms), eventModel(*this) {
network = new Network(); network = new Network();
@ -539,23 +538,6 @@ void MatrixCore::sync() {
i++; 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) { if(firstSync) {
firstSync = false; firstSync = false;
emit initialSyncFinished(); 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() { bool MatrixCore::settingsValid() {
return !network->accessToken.isEmpty() && !network->homeserverURL.isEmpty(); return !network->accessToken.isEmpty() && !network->homeserverURL.isEmpty();
} }
@ -1024,9 +971,6 @@ Member* MatrixCore::resolveMemberId(const QString& id) const {
return idToMember.value(id); return idToMember.value(id);
} }
Community* MatrixCore::resolveCommunityId(const QString &id) const {
return idToCommunity.value(id);
}
Room* MatrixCore::resolveRoomId(const QString &id) const { Room* MatrixCore::resolveRoomId(const QString &id) const {
return idToRoom.value(id); return idToRoom.value(id);
@ -1310,31 +1254,6 @@ void MatrixCore::populateEvent(const QJsonObject& event, Event* e) {
e->setMsg(msg); 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) { QString MatrixCore::getMXCThumbnailURL(QString url) {
const QString imageId = url.remove("mxc://"); const QString imageId = url.remove("mxc://");
return network->homeserverURL + "/_matrix/media/r0/thumbnail/" + imageId + "?width=64&height=64&method=scale"; return network->homeserverURL + "/_matrix/media/r0/thumbnail/" + imageId + "?width=64&height=64&method=scale";
@ -1349,14 +1268,6 @@ QString MatrixCore::getDisplayName() const {
return displayName; 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 { QString MatrixCore::getTypingText() const {
return typingText; return typingText;
} }