2019-04-14 20:37:02 +00:00
|
|
|
/*
|
2019-08-14 14:54:46 +00:00
|
|
|
* Squawk messenger.
|
2019-04-14 20:37:02 +00:00
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CORE_ARCHIVE_H
|
|
|
|
#define CORE_ARCHIVE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2019-10-15 19:25:40 +00:00
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QMimeType>
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
#include "shared/message.h"
|
2021-05-11 17:29:08 +00:00
|
|
|
#include "shared/exception.h"
|
2019-04-16 16:29:24 +00:00
|
|
|
#include <lmdb.h>
|
2019-04-21 19:17:04 +00:00
|
|
|
#include <list>
|
2019-04-14 20:37:02 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
#include <lmdbal/base.h>
|
|
|
|
#include <lmdbal/storage.h>
|
|
|
|
#include <lmdbal/cursor.h>
|
|
|
|
|
2019-04-14 20:37:02 +00:00
|
|
|
namespace Core {
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
class Archive : public QObject {
|
2019-04-14 20:37:02 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-12-30 20:22:04 +00:00
|
|
|
class AvatarInfo;
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
Archive(const QString& account, const QString& jid, QObject* parent = 0);
|
2019-04-14 20:37:02 +00:00
|
|
|
~Archive();
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void open();
|
2019-04-17 20:08:56 +00:00
|
|
|
void close();
|
2019-04-14 20:37:02 +00:00
|
|
|
|
2019-04-21 19:17:04 +00:00
|
|
|
bool addElement(const Shared::Message& message);
|
2019-04-26 12:52:34 +00:00
|
|
|
unsigned int addElements(const std::list<Shared::Message>& messages);
|
2020-05-21 15:42:40 +00:00
|
|
|
Shared::Message getElement(const QString& id) const;
|
2020-08-09 16:28:03 +00:00
|
|
|
bool hasElement(const QString& id) const;
|
2020-03-27 20:59:30 +00:00
|
|
|
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
2023-11-02 22:55:11 +00:00
|
|
|
Shared::Message oldest() const;
|
|
|
|
QString oldestId() const;
|
|
|
|
Shared::Message newest() const;
|
|
|
|
QString newestId() const;
|
2019-04-14 20:37:02 +00:00
|
|
|
void clear();
|
2019-04-15 22:35:09 +00:00
|
|
|
long unsigned int size() const;
|
2023-11-02 22:55:11 +00:00
|
|
|
std::list<Shared::Message> getBefore(unsigned int count, const QString& id);
|
2023-03-16 19:38:05 +00:00
|
|
|
bool isFromTheBeginning() const;
|
2019-05-15 17:36:37 +00:00
|
|
|
void setFromTheBeginning(bool is);
|
2023-03-16 19:38:05 +00:00
|
|
|
bool isEncryptionEnabled() const;
|
|
|
|
bool setEncryptionEnabled(bool is); //returns true if changed, false otherwise
|
2020-04-13 19:57:23 +00:00
|
|
|
bool setAvatar(const QByteArray& data, AvatarInfo& info, bool generated = false, const QString& resource = "");
|
2019-12-30 20:22:04 +00:00
|
|
|
AvatarInfo getAvatarInfo(const QString& resource = "") const;
|
|
|
|
bool readAvatarInfo(AvatarInfo& target, const QString& resource = "") const;
|
2020-04-13 19:57:23 +00:00
|
|
|
void readAllResourcesAvatars(std::map<QString, AvatarInfo>& data) const;
|
2020-05-21 15:42:40 +00:00
|
|
|
QString idByStanzaId(const QString& stanzaId) const;
|
|
|
|
QString stanzaIdById(const QString& id) const;
|
2019-04-14 20:37:02 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
const QString jid;
|
2023-11-02 22:55:11 +00:00
|
|
|
const QString account;
|
2019-04-14 20:37:02 +00:00
|
|
|
|
2019-04-15 22:35:09 +00:00
|
|
|
public:
|
2019-12-30 20:22:04 +00:00
|
|
|
class AvatarInfo {
|
|
|
|
public:
|
|
|
|
AvatarInfo();
|
|
|
|
AvatarInfo(const QString& type, const QByteArray& hash, bool autogenerated);
|
|
|
|
|
|
|
|
QString type;
|
|
|
|
QByteArray hash;
|
|
|
|
bool autogenerated;
|
|
|
|
};
|
|
|
|
|
2019-04-14 20:37:02 +00:00
|
|
|
private:
|
|
|
|
bool opened;
|
2023-11-02 22:55:11 +00:00
|
|
|
LMDBAL::Base db;
|
|
|
|
LMDBAL::Storage<QString, Shared::Message>* messages;
|
|
|
|
LMDBAL::Storage<uint64_t, QString>* order;
|
|
|
|
LMDBAL::Storage<QString, QVariant>* stats;
|
|
|
|
LMDBAL::Storage<QString, AvatarInfo>* avatars;
|
|
|
|
LMDBAL::Storage<QString, QString>* stanzaIdToId;
|
|
|
|
mutable LMDBAL::Cursor<uint64_t, QString> cursor;
|
2019-04-14 20:37:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QDataStream& operator << (QDataStream &out, const Core::Archive::AvatarInfo& info);
|
|
|
|
QDataStream& operator >> (QDataStream &in, Core::Archive::AvatarInfo& info);
|
|
|
|
|
2019-04-14 20:37:02 +00:00
|
|
|
#endif // CORE_ARCHIVE_H
|