forked from blue/squawk
104 lines
3.3 KiB
C++
104 lines
3.3 KiB
C++
/*
|
|
* Squawk messenger.
|
|
* 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>
|
|
#include <QCryptographicHash>
|
|
#include <QMimeDatabase>
|
|
#include <QMimeType>
|
|
|
|
#include "shared/message.h"
|
|
#include "shared/exception.h"
|
|
#include <lmdb.h>
|
|
#include <list>
|
|
|
|
#include <lmdbal/base.h>
|
|
#include <lmdbal/storage.h>
|
|
#include <lmdbal/cursor.h>
|
|
|
|
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<Shared::Message>& messages);
|
|
Shared::Message getElement(const QString& id) const;
|
|
bool hasElement(const QString& id) const;
|
|
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
|
Shared::Message oldest() const;
|
|
QString oldestId() const;
|
|
Shared::Message newest() const;
|
|
QString newestId() const;
|
|
void clear();
|
|
long unsigned int size() const;
|
|
std::list<Shared::Message> getBefore(unsigned int count, const QString& id);
|
|
bool isFromTheBeginning() const;
|
|
void setFromTheBeginning(bool is);
|
|
bool isEncryptionEnabled() const;
|
|
bool setEncryptionEnabled(bool is); //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<QString, AvatarInfo>& 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<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;
|
|
};
|
|
|
|
}
|
|
|
|
QDataStream& operator << (QDataStream &out, const Core::Archive::AvatarInfo& info);
|
|
QDataStream& operator >> (QDataStream &in, Core::Archive::AvatarInfo& info);
|
|
|
|
#endif // CORE_ARCHIVE_H
|