/* * Squawk messenger. * Copyright (C) 2019 Yury Gubich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #include #include #include #include #include "shared/enums.h" #include "shared/message.h" #include "shared/exception.h" #include #include #include #include namespace Core { class Archive : public QObject { Q_OBJECT public: class AvatarInfo; Archive(const QString& account, const QString& jid, QObject* parent = 0); ~Archive(); void open(); void close(); bool addElement(const Shared::Message& message); unsigned int addElements(const std::list& messages); Shared::Message getElement(const QString& id) const; bool hasElement(const QString& id) const; void changeMessage(const QString& id, const QMap& data); Shared::Message oldest() const; QString oldestId() const; Shared::Message newest() const; QString newestId() const; void clear(); long unsigned int size() const; std::list getBefore(unsigned int count, const QString& id); bool isFromTheBeginning() const; void setFromTheBeginning(bool is); Shared::EncryptionProtocol encryption() const; bool setEncryption(Shared::EncryptionProtocol value); //returns true if changed, false otherwise bool setAvatar(const QByteArray& data, AvatarInfo& info, bool generated = false, const QString& resource = ""); AvatarInfo getAvatarInfo(const QString& resource = "") const; bool readAvatarInfo(AvatarInfo& target, const QString& resource = "") const; void readAllResourcesAvatars(std::map& data) const; QString idByStanzaId(const QString& stanzaId) const; QString stanzaIdById(const QString& id) const; public: const QString jid; const QString account; public: class AvatarInfo { public: AvatarInfo(); AvatarInfo(const QString& type, const QByteArray& hash, bool autogenerated); QString type; QByteArray hash; bool autogenerated; }; private: bool opened; LMDBAL::Base db; LMDBAL::Storage* messages; LMDBAL::Storage* order; LMDBAL::Storage* stats; LMDBAL::Storage* avatars; LMDBAL::Storage* stanzaIdToId; mutable LMDBAL::Cursor cursor; }; } QDataStream& operator << (QDataStream &out, const Core::Archive::AvatarInfo& info); QDataStream& operator >> (QDataStream &in, Core::Archive::AvatarInfo& info);