2021-07-21 16:08:15 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
#include "eventmodel.h"
|
|
|
|
#include "room.h"
|
|
|
|
#include "roomlistmodel.h"
|
|
|
|
#include "membermodel.h"
|
|
|
|
#include "roomlistsortmodel.h"
|
|
|
|
#include "emote.h"
|
|
|
|
#include "emotelistmodel.h"
|
2022-03-01 16:20:32 -05:00
|
|
|
#include "encryption.h"
|
|
|
|
|
|
|
|
class Network;
|
2021-07-21 16:08:15 -04:00
|
|
|
|
|
|
|
class MatrixCore : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2022-03-01 16:20:32 -05:00
|
|
|
Q_PROPERTY(QString profileName MEMBER profileName CONSTANT)
|
|
|
|
Q_PROPERTY(bool initialSyncComplete READ isInitialSyncComplete NOTIFY initialSyncFinished)
|
2021-07-21 16:08:15 -04:00
|
|
|
Q_PROPERTY(EventModel* eventModel READ getEventModel NOTIFY currentRoomChanged)
|
|
|
|
Q_PROPERTY(RoomListSortModel* roomListModel READ getRoomListModel NOTIFY roomListChanged)
|
|
|
|
Q_PROPERTY(Room* currentRoom READ getCurrentRoom NOTIFY currentRoomChanged)
|
|
|
|
Q_PROPERTY(QList<Room*> rooms MEMBER rooms NOTIFY roomListChanged)
|
|
|
|
Q_PROPERTY(QString homeserverURL READ getHomeserverURL NOTIFY homeserverChanged)
|
2022-03-01 16:20:32 -05:00
|
|
|
Q_PROPERTY(MemberListSortModel* memberModel READ getMemberModel NOTIFY currentRoomChanged)
|
2021-07-21 16:08:15 -04:00
|
|
|
Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged)
|
|
|
|
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)
|
|
|
|
Q_PROPERTY(EmoteListModel* localEmoteModel READ getLocalEmoteListModel NOTIFY localEmotesChanged)
|
|
|
|
public:
|
2022-03-01 16:20:32 -05:00
|
|
|
MatrixCore(QString profileName, QObject* parent = nullptr);
|
|
|
|
|
|
|
|
Network* network = nullptr;
|
|
|
|
Encryption* encryption = nullptr;
|
2021-07-21 16:08:15 -04:00
|
|
|
|
|
|
|
// account
|
|
|
|
Q_INVOKABLE void registerAccount(const QString& username, const QString& password, const QString& session = "", const QString& type = "");
|
|
|
|
|
|
|
|
Q_INVOKABLE void login(const QString& username, const QString& password);
|
|
|
|
Q_INVOKABLE void logout();
|
|
|
|
|
|
|
|
Q_INVOKABLE void updateAccountInformation();
|
|
|
|
Q_INVOKABLE void setDisplayName(const QString& name);
|
|
|
|
|
|
|
|
// sync
|
|
|
|
Q_INVOKABLE void sync();
|
|
|
|
|
|
|
|
// messaging
|
|
|
|
Q_INVOKABLE void sendMessage(Room* room, const QString& message);
|
|
|
|
Q_INVOKABLE void removeMessage(const QString& eventId);
|
|
|
|
|
|
|
|
Q_INVOKABLE void uploadAttachment(Room* room, const QString& path);
|
|
|
|
|
|
|
|
Q_INVOKABLE void startDirectChat(const QString& id);
|
|
|
|
|
|
|
|
Q_INVOKABLE void setTyping(Room* room);
|
|
|
|
|
|
|
|
// room
|
|
|
|
Q_INVOKABLE void joinRoom(const QString& id);
|
|
|
|
Q_INVOKABLE void leaveRoom(const QString& id);
|
|
|
|
Q_INVOKABLE void inviteToRoom(Room* room, const QString& userId);
|
|
|
|
|
|
|
|
Q_INVOKABLE void updateMembers(Room* room);
|
|
|
|
Q_INVOKABLE void readMessageHistory(Room* room);
|
|
|
|
|
|
|
|
// client related
|
|
|
|
Q_INVOKABLE bool settingsValid();
|
|
|
|
|
|
|
|
Q_INVOKABLE void setHomeserver(const QString& url);
|
|
|
|
|
|
|
|
Q_INVOKABLE void changeCurrentRoom(Room* room);
|
|
|
|
Q_INVOKABLE void changeCurrentRoom(const unsigned int index);
|
|
|
|
|
|
|
|
Q_INVOKABLE void addEmote(const QString& url);
|
|
|
|
Q_INVOKABLE void deleteEmote(Emote* emote);
|
|
|
|
|
|
|
|
Q_INVOKABLE Member* resolveMemberId(const QString& id) const;
|
|
|
|
Q_INVOKABLE Room* resolveRoomId(const QString& id) const;
|
|
|
|
|
|
|
|
Q_INVOKABLE Room* getRoom(const unsigned int index) const;
|
|
|
|
|
|
|
|
Q_INVOKABLE QString getUsername() const;
|
|
|
|
|
2022-03-01 16:20:32 -05:00
|
|
|
Q_INVOKABLE void loadDirectory(const QString& homeserver);
|
2021-07-21 16:08:15 -04:00
|
|
|
|
|
|
|
Q_INVOKABLE void readUpTo(Room* room, const int index);
|
|
|
|
|
2022-03-01 16:20:32 -05:00
|
|
|
Q_INVOKABLE bool isInitialSyncComplete();
|
|
|
|
|
2021-07-21 16:08:15 -04:00
|
|
|
void setMarkdownEnabled(const bool enabled);
|
|
|
|
|
2022-03-01 16:20:32 -05:00
|
|
|
void sendKeyToDevice(QString roomId, QString senderCurveIdentity, QString senderEdIdentity, QString session_id, QString session_key, QString user_id, QString device_id);
|
|
|
|
|
|
|
|
OlmOutboundGroupSession* currentSession = nullptr;
|
|
|
|
QString currentSessionId, currentSessionKey;
|
|
|
|
QString deviceId;
|
|
|
|
void createOrLoadSession();
|
|
|
|
|
|
|
|
QMap<QString, OlmInboundGroupSession*> inboundSessions;
|
|
|
|
|
2021-07-21 16:08:15 -04:00
|
|
|
Room* getCurrentRoom();
|
|
|
|
|
|
|
|
EventModel* getEventModel();
|
|
|
|
RoomListSortModel* getRoomListModel();
|
|
|
|
RoomListSortModel* getDirectoryListModel();
|
2022-03-01 16:20:32 -05:00
|
|
|
MemberListSortModel* getMemberModel();
|
2021-07-21 16:08:15 -04:00
|
|
|
EmoteListModel* getLocalEmoteListModel();
|
|
|
|
|
|
|
|
QString getHomeserverURL() const;
|
|
|
|
|
|
|
|
QString getTypingText() const;
|
|
|
|
|
|
|
|
bool getMarkdownEnabled() const;
|
|
|
|
|
|
|
|
EventModel eventModel;
|
|
|
|
RoomListModel roomListModel, directoryListModel;
|
|
|
|
RoomListSortModel roomListSortModel, directoryListSortModel;
|
|
|
|
MemberModel memberModel;
|
2022-03-01 16:20:32 -05:00
|
|
|
MemberListSortModel memberSortModel;
|
2021-07-21 16:08:15 -04:00
|
|
|
EmoteListModel localEmoteModel;
|
|
|
|
|
|
|
|
Room* currentRoom = nullptr;
|
|
|
|
|
2022-03-01 16:20:32 -05:00
|
|
|
QString profileName;
|
|
|
|
|
2021-07-21 16:08:15 -04:00
|
|
|
signals:
|
|
|
|
void registerAttempt(bool error, QString description);
|
|
|
|
void registerFlow(QJsonObject data);
|
|
|
|
void loginAttempt(bool error, QString description);
|
|
|
|
void syncFinished();
|
|
|
|
void initialSyncFinished();
|
|
|
|
void currentRoomChanged();
|
|
|
|
void roomListChanged();
|
|
|
|
void message(Room* room, QString sender, QString content);
|
|
|
|
void homeserverChanged(bool valid, QString description);
|
|
|
|
void displayNameChanged();
|
|
|
|
void publicRoomsChanged();
|
|
|
|
void typingTextChanged();
|
|
|
|
void markdownEnabledChanged();
|
|
|
|
void localEmotesChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void consumeEvent(const QJsonObject& event, Room& room, const bool insertFront = true);
|
2022-03-01 16:20:32 -05:00
|
|
|
void populateEvent(const QJsonObject& event, Event* e);
|
2021-07-21 16:08:15 -04:00
|
|
|
|
|
|
|
QString getMXCThumbnailURL(QString url);
|
|
|
|
QString getMXCMediaURL(QString url);
|
|
|
|
|
|
|
|
QString getDisplayName() const;
|
|
|
|
|
|
|
|
QList<Room*> rooms;
|
|
|
|
Room emptyRoom;
|
|
|
|
|
|
|
|
QString nextBatch, homeserverURL, userId, displayName;
|
|
|
|
|
|
|
|
QList<QString> invitedRooms, joinedRooms;
|
|
|
|
QList<Room*> publicRooms;
|
|
|
|
|
|
|
|
QList<QString> joinedCommunitiesIds;
|
|
|
|
|
|
|
|
QList<Event*> unsentMessages;
|
|
|
|
|
|
|
|
QMap<QString, Member*> idToMember;
|
|
|
|
QMap<QString, Room*> idToRoom;
|
|
|
|
|
|
|
|
QString typingText;
|
|
|
|
|
|
|
|
QList<Emote*> emotes;
|
|
|
|
|
|
|
|
bool firstSync = true, traversingHistory = false;
|
|
|
|
bool markdownEnabled = true;
|
|
|
|
};
|