// SPDX-FileCopyrightText: 2021 Tobias Fella // SPDX-License-Identifier: LGPL-2.1-or-later #pragma once #include #include #include #include #include "e2ee/e2ee.h" namespace Quotient { class User; class Room; class QUOTIENT_API Database : public QObject { Q_OBJECT public: Database(const QString& matrixId, const QString& deviceId, QObject* parent); int version(); void transaction(); void commit(); QSqlQuery execute(const QString &queryString); QSqlQuery execute(QSqlQuery &query); QSqlDatabase database(); QSqlQuery prepareQuery(const QString& quaryString); QByteArray accountPickle(); void setAccountPickle(const QByteArray &pickle); void clear(); void saveOlmSession(const QString& senderKey, const QString& sessionId, const QByteArray &pickle, const QDateTime& timestamp); UnorderedMap> loadOlmSessions(const PicklingMode& picklingMode); UnorderedMap loadMegolmSessions(const QString& roomId, const PicklingMode& picklingMode); void saveMegolmSession(const QString& roomId, const QString& sessionId, const QByteArray& pickle, const QString& senderId, const QString& olmSessionId); void addGroupSessionIndexRecord(const QString& roomId, const QString& sessionId, uint32_t index, const QString& eventId, qint64 ts); std::pair groupSessionIndexRecord(const QString& roomId, const QString& sessionId, qint64 index); void clearRoomData(const QString& roomId); void setOlmSessionLastReceived(const QString& sessionId, const QDateTime& timestamp); QOlmOutboundGroupSessionPtr loadCurrentOutboundMegolmSession(const QString& roomId, const PicklingMode& picklingMode); void saveCurrentOutboundMegolmSession(const QString& roomId, const PicklingMode& picklingMode, const QOlmOutboundGroupSessionPtr& data); // Returns a map User -> [Device] that have not received key yet QHash devicesWithoutKey(Room* room, const QString &sessionId); void setDevicesReceivedKey(const QString& roomId, QHash devices, const QString& sessionId, int index); private: void migrateTo1(); void migrateTo2(); void migrateTo3(); QString m_matrixId; }; }